feat: onboarding & profile edition (#507)
* feat: wip onboarding * fix: generate graphql front * wip: onboarding * feat: login/register and edit profile * fix: unused import * fix: test * Use DEBUG_MODE instead of STAGE and mute typescript depth exceed errors * Fix seeds * Fix onboarding when coming from google * Fix * Fix lint * Fix ci * Fix tests --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -1,4 +1,11 @@
|
||||
import { Args, Resolver, Query, ResolveField, Parent } from '@nestjs/graphql';
|
||||
import {
|
||||
Args,
|
||||
Resolver,
|
||||
Query,
|
||||
ResolveField,
|
||||
Parent,
|
||||
Mutation,
|
||||
} from '@nestjs/graphql';
|
||||
import { UserService } from './user.service';
|
||||
import { FindManyUserArgs } from 'src/core/@generated/user/find-many-user.args';
|
||||
import { User } from 'src/core/@generated/user/user.model';
|
||||
@ -11,16 +18,40 @@ import {
|
||||
} from 'src/decorators/prisma-select.decorator';
|
||||
import { AbilityGuard } from 'src/guards/ability.guard';
|
||||
import { CheckAbilities } from 'src/decorators/check-abilities.decorator';
|
||||
import { ReadUserAbilityHandler } from 'src/ability/handlers/user.ability-handler';
|
||||
import {
|
||||
ReadUserAbilityHandler,
|
||||
UpdateUserAbilityHandler,
|
||||
} from 'src/ability/handlers/user.ability-handler';
|
||||
import { UserAbility } from 'src/decorators/user-ability.decorator';
|
||||
import { AppAbility } from 'src/ability/ability.factory';
|
||||
import { accessibleBy } from '@casl/prisma';
|
||||
import { AuthUser } from 'src/decorators/auth-user.decorator';
|
||||
import { assert } from 'src/utils/assert';
|
||||
import { UpdateOneUserArgs } from '../@generated/user/update-one-user.args';
|
||||
import { Prisma } from '@prisma/client';
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Resolver(() => User)
|
||||
export class UserResolver {
|
||||
constructor(private readonly userService: UserService) {}
|
||||
|
||||
@Query(() => User)
|
||||
async currentUser(
|
||||
@AuthUser() { id }: User,
|
||||
@PrismaSelector({ modelName: 'User' })
|
||||
prismaSelect: PrismaSelect<'User'>,
|
||||
) {
|
||||
const user = await this.userService.findUnique({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
select: prismaSelect.value,
|
||||
});
|
||||
assert(user, 'User not found');
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
@UseFilters(ExceptionFilter)
|
||||
@Query(() => [User], {
|
||||
nullable: false,
|
||||
@ -34,16 +65,44 @@ export class UserResolver {
|
||||
prismaSelect: PrismaSelect<'User'>,
|
||||
): Promise<Partial<User>[]> {
|
||||
return await this.userService.findMany({
|
||||
...args,
|
||||
where: args.where
|
||||
? {
|
||||
AND: [args.where, accessibleBy(ability).User],
|
||||
}
|
||||
: accessibleBy(ability).User,
|
||||
orderBy: args.orderBy,
|
||||
cursor: args.cursor,
|
||||
take: args.take,
|
||||
skip: args.skip,
|
||||
distinct: args.distinct,
|
||||
select: prismaSelect.value,
|
||||
});
|
||||
}
|
||||
|
||||
@Mutation(() => User)
|
||||
@UseGuards(AbilityGuard)
|
||||
@CheckAbilities(UpdateUserAbilityHandler)
|
||||
async updateUser(
|
||||
@Args() args: UpdateOneUserArgs,
|
||||
@AuthUser() { id }: User,
|
||||
@PrismaSelector({ modelName: 'User' })
|
||||
prismaSelect: PrismaSelect<'User'>,
|
||||
) {
|
||||
const user = await this.userService.findUnique({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
select: prismaSelect.value,
|
||||
});
|
||||
assert(user, 'User not found');
|
||||
|
||||
return this.userService.update({
|
||||
where: args.where,
|
||||
data: args.data,
|
||||
select: prismaSelect.value,
|
||||
} as Prisma.UserUpdateArgs);
|
||||
}
|
||||
|
||||
@ResolveField(() => String, {
|
||||
nullable: false,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user