Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions src/api/routes/users/#id/consents/#service_id/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,23 @@ import { UserConsent } from "@spacebar/util";
const router: Router = Router();

router.delete(
"/",
route({
right: "MANAGE_USERS",
summary:
"Revoke consent for a service for the specified user (admin only)",
responses: { 204: { body: "null" } },
}),
async (req: Request, res: Response) => {
const user_id = req.params.id;
const service_id = req.params.service_id;
const existing = await UserConsent.findOne({
where: { user_id, service_id },
});
if (existing) {
await existing.remove();
}
return res.status(204).send();
},
"/",
route({
right: "MANAGE_USERS",
summary: "Revoke consent for a service for the specified user (admin only)",
responses: { 204: { body: "null" } },
}),
async (req: Request, res: Response) => {
const user_id = req.params.id;
const service_id = req.params.service_id;
const existing = await UserConsent.findOne({
where: { user_id, service_id },
});
if (existing) {
await existing.remove();
}
return res.status(204).send();
},
);

export default router;
70 changes: 35 additions & 35 deletions src/api/routes/users/#id/consents/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,44 @@ import { UserConsent } from "@spacebar/util";
const router: Router = Router();

router.get(
"/",
route({
right: "MANAGE_USERS",
summary: "List consents for a specified user (admin only)",
responses: {
200: { body: "any" },
403: { body: "APIErrorResponse" },
},
}),
async (req: Request, res: Response) => {
const target_user_id = req.params.id;
const consents = await UserConsent.find({
where: { user_id: target_user_id },
});
res.json(
consents.map((c) => ({
service_id: c.service_id,
consented_at: c.created_at,
})),
);
},
"/",
route({
right: "MANAGE_USERS",
summary: "List consents for a specified user (admin only)",
responses: {
200: { body: "any" },
403: { body: "APIErrorResponse" },
},
}),
async (req: Request, res: Response) => {
const target_user_id = req.params.id;
const consents = await UserConsent.find({
where: { user_id: target_user_id },
});
res.json(
consents.map((c) => ({
service_id: c.service_id,
consented_at: c.created_at,
})),
);
},
);

router.delete(
"/",
route({
right: "OPERATOR",
summary: "Revoke all consents for a specified user (operator only)",
responses: {
204: { body: "null" },
403: { body: "APIErrorResponse" },
},
}),
async (req: Request, res: Response) => {
const target_user_id = req.params.id;
await UserConsent.delete({ user_id: target_user_id });
return res.status(204).send();
},
"/",
route({
right: "OPERATOR",
summary: "Revoke all consents for a specified user (operator only)",
responses: {
204: { body: "null" },
403: { body: "APIErrorResponse" },
},
}),
async (req: Request, res: Response) => {
const target_user_id = req.params.id;
await UserConsent.delete({ user_id: target_user_id });
return res.status(204).send();
},
);

export default router;
Loading
Loading