Skip to content

Commit e6d0885

Browse files
committed
Revert "added user meta field to the noteHistoryMeta"
This reverts commit 0b405b6.
1 parent 0b405b6 commit e6d0885

5 files changed

Lines changed: 11 additions & 62 deletions

File tree

src/domain/entities/noteHistory.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
import type { NoteInternalId, Note, NotePublicId } from './note.js';
22
import type User from './user.js';
33

4-
interface UserMeta {
5-
/**
6-
* Name of the user
7-
*/
8-
name: User['name'];
9-
10-
/**
11-
* Photo of the user
12-
*/
13-
photo: User['photo'];
14-
};
15-
164
export interface NoteHistoryRecord {
175
/**
186
* Unique identified of note history record
@@ -54,13 +42,7 @@ export type NoteHistoryCreationAttributes = Omit<NoteHistoryRecord, 'id' | 'crea
5442
* Meta data of the note history record
5543
* Used for presentation of the note history record in web
5644
*/
57-
export type NoteHistoryMeta = Omit<NoteHistoryRecord, 'content' | 'noteId' | 'tools'> & {
58-
/**
59-
* Meta data of the user who did changes
60-
* Used for note history metadata presentation
61-
*/
62-
user: UserMeta;
63-
};
45+
export type NoteHistoryMeta = Omit<NoteHistoryRecord, 'content' | 'noteId' | 'tools'>;
6446

6547
/**
6648
* Public note history record with note public id instead of note internal id

src/presentation/http/router/note.test.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,22 +1977,15 @@ describe('Note API', () => {
19771977
expect(response?.json()).toStrictEqual({ message: expectedMessage });
19781978
} else {
19791979
expect(response?.json().noteHistoryMeta).toHaveLength(2);
1980-
expect(response?.json().noteHistoryMeta[1]).toMatchObject({
1980+
expect(response?.json().noteHistoryMeta[0]).toMatchObject({
1981+
id: 1,
19811982
userId: creator.id,
1982-
user: {
1983-
name: creator.name,
1984-
photo: creator.photo,
1985-
},
19861983
});
19871984

1988-
expect(response?.json().noteHistoryMeta[0]).toMatchObject({
1985+
expect(response?.json().noteHistoryMeta[1]).toMatchObject({
19891986
id: history.id,
19901987
userId: history.userId,
19911988
createdAt: history.createdAt,
1992-
user: {
1993-
name: creator.name,
1994-
photo: creator.photo,
1995-
},
19961989
});
19971990
}
19981991
});

src/presentation/http/schema/History.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,5 @@ export const HistoryMetaSchema = {
8484
type: 'string',
8585
format: 'date-time',
8686
},
87-
user: {
88-
type: 'object',
89-
properties: {
90-
name: {
91-
description: 'name of the user',
92-
type: 'string',
93-
},
94-
photo: {
95-
description: 'photo of the user',
96-
type: 'string',
97-
},
98-
},
99-
},
10087
},
10188
};

src/repository/storage/postgres/orm/sequelize/noteHistory.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ export class NoteHistoryModel extends Model<InferAttributes<NoteHistoryModel>, I
4444
export 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
/**

src/tests/utils/database-helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ export default class DatabaseHelpers {
193193
const name = user?.name ?? `CodeX-${randomPart}`;
194194
const email = user?.email ?? `${randomPart}@codexmail.com`;
195195

196-
const [results, _] = await this.orm.connection.query(`INSERT INTO public.users ("email", "name", "created_at", "editor_tools", "photo")
197-
VALUES ('${email}', '${name}', CLOCK_TIMESTAMP(), '${editorTools}'::jsonb, '')
196+
const [results, _] = await this.orm.connection.query(`INSERT INTO public.users ("email", "name", "created_at", "editor_tools")
197+
VALUES ('${email}', '${name}', CLOCK_TIMESTAMP(), '${editorTools}'::jsonb)
198198
RETURNING "id", "email", "name", "editor_tools" AS "editorTools", "created_at" AS "createdAt", "photo"`,
199199
{
200200
type: QueryTypes.INSERT,

0 commit comments

Comments
 (0)