feat: refactor folder structure (#4498)
* feat: wip refactor folder structure * Fix * fix position --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -0,0 +1,11 @@
|
||||
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
|
||||
|
||||
import { getRequest } from 'src/utils/extract-request';
|
||||
|
||||
export const UserAbility = createParamDecorator(
|
||||
(_: unknown, context: ExecutionContext) => {
|
||||
const request = getRequest(context);
|
||||
|
||||
return request.ability;
|
||||
},
|
||||
);
|
||||
@ -0,0 +1,23 @@
|
||||
import {
|
||||
ExecutionContext,
|
||||
ForbiddenException,
|
||||
createParamDecorator,
|
||||
} from '@nestjs/common';
|
||||
|
||||
import { getRequest } from 'src/utils/extract-request';
|
||||
|
||||
interface DecoratorOptions {
|
||||
allowUndefined?: boolean;
|
||||
}
|
||||
|
||||
export const AuthUser = createParamDecorator(
|
||||
(options: DecoratorOptions | undefined, ctx: ExecutionContext) => {
|
||||
const request = getRequest(ctx);
|
||||
|
||||
if (!options?.allowUndefined && (!request.user || !request.user.user)) {
|
||||
throw new ForbiddenException("You're not authorized to do this");
|
||||
}
|
||||
|
||||
return request.user ? request.user.user : undefined;
|
||||
},
|
||||
);
|
||||
@ -0,0 +1,11 @@
|
||||
import { ExecutionContext, createParamDecorator } from '@nestjs/common';
|
||||
|
||||
import { getRequest } from 'src/utils/extract-request';
|
||||
|
||||
export const AuthWorkspace = createParamDecorator(
|
||||
(data: unknown, ctx: ExecutionContext) => {
|
||||
const request = getRequest(ctx);
|
||||
|
||||
return request.user ? request.user.workspace : undefined;
|
||||
},
|
||||
);
|
||||
Reference in New Issue
Block a user