@@ -3,7 +3,7 @@ import { DataTypes, literal, Model } from 'sequelize';
33import type Orm from '@repository/storage/postgres/orm/sequelize/index.js' ;
44import { NoteModel } from './note.js' ;
55import { UserModel } from './user.js' ;
6- import type { NoteHistoryCreationAttributes , NoteHistoryRecord , NoteHistoryMeta } from '@domain/entities/noteHistory.js' ;
6+ import type { NoteHistoryCreationAttributes , NoteHistoryRecord , NoteHistoryMeta , NoteHistoryView } from '@domain/entities/noteHistory.js' ;
77
88/**
99 * Note history model instance
@@ -162,8 +162,24 @@ export default class NoteHistorySequelizeStorage {
162162 * @param id - id of the history record
163163 * @returns full history record or null if there is no record with such an id
164164 */
165- public async getHistoryRecordById ( id : NoteHistoryRecord [ 'id' ] ) : Promise < NoteHistoryRecord | null > {
166- return await this . model . findByPk ( id ) ;
165+ public async getHistoryRecordById ( id : NoteHistoryRecord [ 'id' ] ) : Promise < NoteHistoryView | null > {
166+ const historyView = await this . model . findOne ( {
167+ where : {
168+ id,
169+ } ,
170+ include : {
171+ model : this . userModel ,
172+ as : 'user' ,
173+ attributes : [ 'name' , 'photo' ] ,
174+ } ,
175+ } ) ;
176+
177+ /**
178+ * We need this cast because of using sequelize model.include
179+ * Since it returns NoteHistoryModel[], however we included userModel,
180+ * without this cast NoteHistoryModel[] and NoteHistoryView are incompatible
181+ */
182+ return historyView as unknown as NoteHistoryView ;
167183 }
168184
169185 /**
0 commit comments