@@ -44,9 +44,9 @@ export class NoteHistoryModel extends Model<InferAttributes<NoteHistoryModel>, I
4444export default class NoteHistorySequelizeStorage {
4545 public model : typeof NoteHistoryModel ;
4646
47- public userModel : typeof UserModel | undefined = undefined ;
47+ public userModel : typeof UserModel | null = null ;
4848
49- public noteModel : typeof NoteModel | undefined = undefined ;
49+ public noteModel : typeof NoteModel | null = null ;
5050
5151 private readonly database : Sequelize ;
5252
@@ -96,7 +96,7 @@ export default class NoteHistorySequelizeStorage {
9696
9797 this . model . belongsTo ( this . userModel , {
9898 foreignKey : 'userId' ,
99- as : 'user' ,
99+ as : this . userModel . tableName ,
100100 } ) ;
101101 }
102102
@@ -109,7 +109,7 @@ export default class NoteHistorySequelizeStorage {
109109
110110 this . model . belongsTo ( this . noteModel , {
111111 foreignKey : 'noteId' ,
112- as : 'note' ,
112+ as : this . noteModel . tableName ,
113113 } ) ;
114114 }
115115
@@ -139,23 +139,10 @@ export default class NoteHistorySequelizeStorage {
139139 * @returns array of metadata of the history records
140140 */
141141 public async getNoteHistoryByNoteId ( noteId : NoteHistoryRecord [ 'noteId' ] ) : Promise < NoteHistoryMeta [ ] > {
142- const historyMeta = await this . model . findAll ( {
142+ return await this . model . findAll ( {
143143 where : { noteId } ,
144144 attributes : [ 'id' , 'userId' , 'createdAt' ] ,
145- include : {
146- model : this . userModel ,
147- as : 'user' ,
148- attributes : [ 'name' , 'photo' ] ,
149- } ,
150- raw : true ,
151145 } ) ;
152-
153- /**
154- * We need this cast because of using sequelize model.include
155- * Since it returns NoteHistoryModel[], however we included userModel,
156- * without this cast NoteHistoryModel[] and NoteHistoryMeta[] are incompatible
157- */
158- return historyMeta as unknown as NoteHistoryMeta [ ] ;
159146 }
160147
161148 /**
0 commit comments