Skip to content

Commit

Permalink
fix: apply PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
spaenleh committed Oct 20, 2023
1 parent d1a2734 commit 0768ed3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/mockServer/msw/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ export const buildMSWMocks = (
return res(ctx.status(403), ctx.json({ message: 'member can not admin' }));
}

// todo: check that is admin
const body: Pick<AppSetting, 'data' | 'id'> = await req.json();
const appSetting: Partial<MockAppSetting> = {
updatedAt: new Date(),
Expand All @@ -249,6 +248,14 @@ export const buildMSWMocks = (
async (req, res, ctx) => {
const { id } = req.params;

const memberId = getMemberIdFromToken(req.headers.get('Authorization'));
const permission = await getPermissionForMember(memberId);

// when member is not an admin -> return an error
if (PermissionLevel.Admin !== permission) {
return res(ctx.status(403), ctx.json({ message: 'member can not admin' }));
}

const value = await db.appSetting.get(id as string);
await db.appSetting.delete(id as string);

Expand Down Expand Up @@ -318,7 +325,7 @@ export const buildMSWMocks = (
}),

// plumbing
rest.delete('/__mocks/reset', (req, res, ctx) => {
rest.delete('/__mocks/reset', (_req, res, ctx) => {
db.resetDB(database);
return res(ctx.status(200));
}),
Expand All @@ -330,7 +337,6 @@ export const buildMSWMocks = (
rest.post('/__mocks/context', async (req, res, ctx) => {
const memberId = getMemberIdFromToken(req.headers.get('Authorization'));
const body: Partial<LocalContext> = await req.json();
console.log(body);
await db.appContext.update(memberId, body);

const value = await db.appContext.where('memberId').equals(memberId).first();
Expand Down
4 changes: 2 additions & 2 deletions src/mockServer/msw/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const mockServiceWorkerServer = ({
if (database) {
// seed database with data
// eslint-disable-next-line no-console
console.info('Populating the DB with provided mock data');
console.debug('Populating the DB with provided mock data');
if (database.items.length) {
transaction.table('item').bulkAdd(database?.items);
}
Expand All @@ -39,7 +39,7 @@ export const mockServiceWorkerServer = ({
transaction.table('appContext').add(database.appContext, database.appContext.memberId);
} else {
// eslint-disable-next-line no-console
console.log('There was no data to populate the database');
console.debug('There was no data to populate the database');
}
});

Expand Down

0 comments on commit 0768ed3

Please sign in to comment.