diff --git a/src/mockServer/msw/handlers.ts b/src/mockServer/msw/handlers.ts index 00c975cb..8527e719 100644 --- a/src/mockServer/msw/handlers.ts +++ b/src/mockServer/msw/handlers.ts @@ -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 = await req.json(); const appSetting: Partial = { updatedAt: new Date(), @@ -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); @@ -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)); }), @@ -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 = await req.json(); - console.log(body); await db.appContext.update(memberId, body); const value = await db.appContext.where('memberId').equals(memberId).first(); diff --git a/src/mockServer/msw/server.ts b/src/mockServer/msw/server.ts index 5d518fcb..1ebff3da 100644 --- a/src/mockServer/msw/server.ts +++ b/src/mockServer/msw/server.ts @@ -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); } @@ -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'); } });