async read(req: AuthenticatedRequest, res: FastifyReply, id: string) {
const hasReadPermissions = await this.app.auth.api.userHasPermission({
body: {
userId: req.user.id,
permission: {
userProfile: ["read"],
},
},
});
if (!hasReadPermissions.success) {
throw this.app.httpErrors.forbidden();
}
if (req.user.id !== id) {
const hasReadAllPermissions = await this.app.auth.api.userHasPermission({
body: {
userId: req.user.id,
permission: {
userProfile: ["read:all", "asd"],
},
},
});
if (!hasReadAllPermissions.success) {
throw this.app.httpErrors.forbidden();
}
}
const profile = await this.app.db.query.userProfile.findFirst({
where: eq(userProfile.id, id),
});
if (!profile) {
throw this.app.httpErrors.notFound();
}
return profile;
}
async read(req: AuthenticatedRequest, res: FastifyReply, id: string) {
const hasReadPermissions = await this.app.auth.api.userHasPermission({
body: {
userId: req.user.id,
permission: {
userProfile: ["read"],
},
},
});
if (!hasReadPermissions.success) {
throw this.app.httpErrors.forbidden();
}
if (req.user.id !== id) {
const hasReadAllPermissions = await this.app.auth.api.userHasPermission({
body: {
userId: req.user.id,
permission: {
userProfile: ["read:all", "asd"],
},
},
});
if (!hasReadAllPermissions.success) {
throw this.app.httpErrors.forbidden();
}
}
const profile = await this.app.db.query.userProfile.findFirst({
where: eq(userProfile.id, id),
});
if (!profile) {
throw this.app.httpErrors.notFound();
}
return profile;
}