Skip to content

Commit

Permalink
type error fixed
Browse files Browse the repository at this point in the history
- type of role changed to typeof keyof MemberRole
- fixed some test data
  • Loading branch information
e11sy committed Jan 11, 2024
1 parent 3b2f106 commit 17d311d
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 33 deletions.
12 changes: 1 addition & 11 deletions src/domain/service/noteSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,7 @@ export default class NoteSettingsService {
* @param noteId - note internal id
* @param role - new team member role
*/
public async patchMemberRoleByUserId(id: TeamMember['id'], noteId: NoteInternalId, role : MemberRole): Promise<TeamMember['role'] | null> {
return await this.teamRepository.patchMemberRoleByUserId(id, noteId, role);
}

/**
*
* @param id - id of team member
* @param noteId - note internal id
* @param role - new team member role
*/
public async patchMemberRoleByUserId(id: TeamMember['id'], noteId: NoteInternalId, role : MemberRole): Promise<TeamMember['role'] | null> {
public async patchMemberRoleByUserId(id: TeamMember['id'], noteId: NoteInternalId, role : keyof typeof MemberRole): Promise<keyof typeof MemberRole | null> {
return await this.teamRepository.patchMemberRoleByUserId(id, noteId, role);
}
}
2 changes: 1 addition & 1 deletion src/presentation/http/router/join.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('Join API', () => {

expect(response?.json()).toStrictEqual({
result: {
id: 2,
id: 3,
userId,
noteId: 1,
role: 0,
Expand Down
10 changes: 5 additions & 5 deletions src/presentation/http/router/noteSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ describe('NoteSettings API', () => {
},
url: '/note-settings/new-role/write',
body: {
'userId': 3,
'userId': 1,
'noteId': 2,
},
});
Expand All @@ -307,9 +307,9 @@ describe('NoteSettings API', () => {
if (team?.json() !== undefined) {
expect(team?.json()).toStrictEqual([
{
'id': 1,
'id': 2,
'noteId': 2,
'userId': 3,
'userId': 1,
'role': 1,
},
]);
Expand All @@ -324,7 +324,7 @@ describe('NoteSettings API', () => {
},
url: '/note-settings/new-role/write',
body: {
'userId': 3,
'userId': 1,
'noteId': 2,
},
});
Expand All @@ -333,7 +333,7 @@ describe('NoteSettings API', () => {
expect(response?.body).toBe('write');
});

test('returns 404 and User in team not found message if no such a note exists', async () => {
test('returns 404 and User in team is not found message if no such a note exists', async () => {
const response = await global.api?.fakeRequest({
method: 'PATCH',
headers: {
Expand Down
6 changes: 3 additions & 3 deletions src/presentation/http/router/noteSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import useNoteResolver from '../middlewares/note/useNoteResolver.js';
import type NoteService from '@domain/service/note.js';
import useNoteSettingsResolver from '../middlewares/noteSettings/useNoteSettingsResolver.js';
import type { NoteInternalId, NotePublicId } from '@domain/entities/note.js';
import type { Team, TeamMember } from '@domain/entities/team.js';
import type { Team, MemberRole } from '@domain/entities/team.js';;
import type User from '@domain/entities/user.js';

/**
Expand Down Expand Up @@ -99,9 +99,9 @@ const NoteSettingsRouter: FastifyPluginCallback<NoteSettingsRouterOptions> = (fa
noteId: NoteInternalId,
}
Params: {
newRole: TeamMember['role'],
newRole: keyof typeof MemberRole,
},
Reply: TeamMember['role'],
Reply: keyof typeof MemberRole,
}>('/new-role/:newRole', {
config: {
policy: [
Expand Down
5 changes: 4 additions & 1 deletion src/repository/storage/postgres/orm/sequelize/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,10 @@ export default class TeamsSequelizeStorage {
* @param noteId - note internal id
* @param role - new team member role
*/
public async patchMemberRoleById(userId: TeamMember['id'], noteId: NoteInternalId, role: MemberRole): Promise<TeamMember['role'] | null> {
public async patchMemberRoleById(userId: TeamMember['id'], noteId: NoteInternalId, role: keyof typeof MemberRole): Promise<keyof typeof MemberRole | null> {
console.log('======================');
console.log(typeof role);
console.log('======================');
const affectedRows = await this.model.update({
role: MemberRole[role],
}, {
Expand Down
2 changes: 1 addition & 1 deletion src/repository/team.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default class TeamRepository {
* @param noteId - note internal id
* @param role - team member new role
*/
public async patchMemberRoleByUserId(id: TeamMember['id'], noteId: NoteInternalId, role : MemberRole): Promise<TeamMember['role'] | null> {
public async patchMemberRoleByUserId(id: TeamMember['id'], noteId: NoteInternalId, role : keyof typeof MemberRole): Promise<keyof typeof MemberRole | null> {
return await this.storage.patchMemberRoleById(id, noteId, role);
}
}
6 changes: 6 additions & 0 deletions src/tests/test-data/note-teams.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@
"note_id": 1,
"user_id": 2,
"role": 0
},
{
"id": 2,
"note_id": 2,
"user_id": 1,
"role": 0
}
]
11 changes: 0 additions & 11 deletions src/tests/utils/insert-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,6 @@ async function insertNoteSettings(db: SequelizeOrm): Promise<void> {
}
}

/**
* Fills in the database with note teams data
*
* @param db - SequelizeOrm instance
*/
async function insertNoteTeams(db: SequelizeOrm): Promise<void> {
for (const noteTeam of noteTeams) {
await db.connection.query(`INSERT INTO public.note_teams ("note_id", "user_id", "role") VALUES (${noteTeam.note_id}, ${noteTeam.user_id}, '${noteTeam.role}')`);
}
}


/**
* Fills in the database with test data
Expand Down

0 comments on commit 17d311d

Please sign in to comment.