chore: Adds formatting.
Co-authored-by: dess <devessa@users.noreply.github.com>
This commit is contained in:
parent
6cf26da4df
commit
42a6d2ea02
33 changed files with 1235 additions and 1032 deletions
|
@ -2,65 +2,66 @@ import { hasPermissionByToken } from "../../libs/permissions.js";
|
|||
import type { RouteOptions } from "../../libs/types.js";
|
||||
|
||||
export function route(routeOptions: RouteOptions) {
|
||||
const {
|
||||
fastify,
|
||||
prisma,
|
||||
tokens
|
||||
} = routeOptions;
|
||||
const { fastify, prisma, tokens } = routeOptions;
|
||||
|
||||
function hasPermission(token: string, permissionList: string[]): Promise<boolean> {
|
||||
function hasPermission(
|
||||
token: string,
|
||||
permissionList: string[],
|
||||
): Promise<boolean> {
|
||||
return hasPermissionByToken(permissionList, token, tokens, prisma);
|
||||
};
|
||||
}
|
||||
|
||||
fastify.post("/api/v1/users/lookup", {
|
||||
schema: {
|
||||
body: {
|
||||
type: "object",
|
||||
required: ["token"],
|
||||
fastify.post(
|
||||
"/api/v1/users/lookup",
|
||||
{
|
||||
schema: {
|
||||
body: {
|
||||
type: "object",
|
||||
required: ["token"],
|
||||
|
||||
properties: {
|
||||
token: { type: "string" },
|
||||
id: { type: "number" },
|
||||
name: { type: "string" },
|
||||
email: { type: "string" },
|
||||
isServiceAccount: { type: "boolean" }
|
||||
}
|
||||
properties: {
|
||||
token: { type: "string" },
|
||||
id: { type: "number" },
|
||||
name: { type: "string" },
|
||||
email: { type: "string" },
|
||||
isServiceAccount: { type: "boolean" },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
async (req, res) => {
|
||||
// @ts-ignore
|
||||
const body: {
|
||||
token: string;
|
||||
id?: number;
|
||||
name?: string;
|
||||
email?: string;
|
||||
isServiceAccount?: boolean;
|
||||
} = req.body;
|
||||
|
||||
if (!(await hasPermission(body.token, ["users.lookup"]))) {
|
||||
return res.status(403).send({
|
||||
error: "Unauthorized",
|
||||
});
|
||||
}
|
||||
}
|
||||
}, async(req, res) => {
|
||||
// @ts-ignore
|
||||
const body: {
|
||||
token: string,
|
||||
id?: number,
|
||||
name?: string,
|
||||
email?: string,
|
||||
isServiceAccount?: boolean
|
||||
} = req.body;
|
||||
|
||||
if (!await hasPermission(body.token, [
|
||||
"users.lookup"
|
||||
])) {
|
||||
return res.status(403).send({
|
||||
error: "Unauthorized"
|
||||
const users = await prisma.user.findMany({
|
||||
where: {
|
||||
id: body.id,
|
||||
name: body.name,
|
||||
email: body.email,
|
||||
isRootServiceAccount: body.isServiceAccount,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const users = await prisma.user.findMany({
|
||||
where: {
|
||||
id: body.id,
|
||||
name: body.name,
|
||||
email: body.email,
|
||||
isRootServiceAccount: body.isServiceAccount
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: users.map((i) => ({
|
||||
name: i.name,
|
||||
email: i.email,
|
||||
isServiceAccount: i.isRootServiceAccount
|
||||
}))
|
||||
}
|
||||
});
|
||||
}
|
||||
return {
|
||||
success: true,
|
||||
data: users.map(i => ({
|
||||
name: i.name,
|
||||
email: i.email,
|
||||
isServiceAccount: i.isRootServiceAccount,
|
||||
})),
|
||||
};
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue