mirror of
https://github.com/documenso/documenso.git
synced 2025-11-24 05:32:12 +10:00
feat: doc comments
This commit is contained in:
33
packages/lib/server-only/auth/api-auth-middleware.ts
Normal file
33
packages/lib/server-only/auth/api-auth-middleware.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { getUserByApiToken } from '@documenso/lib/server-only/public-api/get-user-by-token';
|
||||
|
||||
export type Headers = {
|
||||
headers: {
|
||||
authorization: string;
|
||||
};
|
||||
};
|
||||
|
||||
export const authenticatedMiddleware = <T extends Headers>(fn: (args: T) => Promise<any>) => {
|
||||
return async (args: T) => {
|
||||
if (!args.headers.authorization) {
|
||||
return {
|
||||
status: 401,
|
||||
body: {
|
||||
message: 'Unauthorized access',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
await getUserByApiToken({ token: args.headers.authorization });
|
||||
} catch (err) {
|
||||
return {
|
||||
status: 401,
|
||||
body: {
|
||||
message: 'Unauthorized access',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return fn(args);
|
||||
};
|
||||
};
|
||||
25
packages/lib/server-only/comment/find-comments.ts
Normal file
25
packages/lib/server-only/comment/find-comments.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
export const findComments = async () => {
|
||||
return await prisma.documentComment.findMany({
|
||||
where: {
|
||||
parentId: null,
|
||||
},
|
||||
include: {
|
||||
User: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
replies: {
|
||||
include: {
|
||||
User: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user