mirror of
https://github.com/elicpeter/nyx.git
synced 2026-06-15 20:05:13 +02:00
38 lines
1.2 KiB
JavaScript
38 lines
1.2 KiB
JavaScript
|
|
const Router = require("@koa/router");
|
||
|
|
const koaRouter = new Router();
|
||
|
|
const fastify = require("fastify")();
|
||
|
|
const requireLogin = require("./auth").requireLogin;
|
||
|
|
|
||
|
|
koaRouter.post("/admin/users/:id/role", requireLogin, async (ctx) => {
|
||
|
|
await adminService.updateUserRole(ctx.params.id, ctx.request.body.role);
|
||
|
|
ctx.body = { ok: true };
|
||
|
|
});
|
||
|
|
|
||
|
|
fastify.route({
|
||
|
|
method: "POST",
|
||
|
|
url: "/projects/:projectId/state",
|
||
|
|
preValidation: requireLogin,
|
||
|
|
handler: async function updateProjectState(request, reply) {
|
||
|
|
const project = await projectModel.updateState(request.params.projectId, request.body);
|
||
|
|
reply.send({ project });
|
||
|
|
},
|
||
|
|
});
|
||
|
|
|
||
|
|
async function acceptInvitation(token, currentUser, roleOverride) {
|
||
|
|
const invitation = await invitationModel.findByToken(token);
|
||
|
|
if (Date.now() < invitation.expires_at && invitation.email === currentUser.email) {
|
||
|
|
return workspaceModel.addMembership(
|
||
|
|
invitation.workspace_id,
|
||
|
|
currentUser.id,
|
||
|
|
roleOverride || invitation.requested_role,
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
async function bulkArchive(userId, ids) {
|
||
|
|
await checkMembership(userId, ids[0]);
|
||
|
|
return projectModel.archiveByIds(ids);
|
||
|
|
}
|
||
|
|
|
||
|
|
module.exports = { koaRouter, fastify, acceptInvitation, bulkArchive };
|