Skip to content

Commit

Permalink
refactor: added schema for delete tool, added some comments, changed …
Browse files Browse the repository at this point in the history
…response object
  • Loading branch information
slaveeks committed Feb 23, 2024
1 parent 4ab2ab3 commit 5b4e277
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/presentation/http/router/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,20 @@ const UserRouter: FastifyPluginCallback<UserRouterOptions> = (fastify, opts, don
description: 'Unique editor tool id',
},
},
response: {
'2xx': {
description: 'Removed editor tool id',
content: {
'application/json': {
schema: {
removeId: {
type: 'string',
},
},
},
},
},
},
},
}, async (request, reply) => {
const toolId = request.body.toolId;
Expand All @@ -163,7 +177,7 @@ const UserRouter: FastifyPluginCallback<UserRouterOptions> = (fastify, opts, don
});

return reply.send({
data: toolId,
removeId: toolId,
});
});

Expand Down
7 changes: 6 additions & 1 deletion src/repository/storage/postgres/orm/sequelize/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,12 @@ export default class UserSequelizeStorage {
toolId,
}: AddUserToolOptions): Promise<void> {
await this.model.update({
editorTools: literal(`COALESCE(editor_tools, '[]'::jsonb) || '["${toolId}"]'::jsonb`),
editorTools: literal(
/**
* If editorTools is null, then set it to empty array
* Then add the tool to the list
*/
`COALESCE(editor_tools, '[]'::jsonb) || '["${toolId}"]'::jsonb`),
}, {
where: {
id: userId,
Expand Down

0 comments on commit 5b4e277

Please sign in to comment.