feat: add findAll and findUnique resolver for universal objects (#1576)
* wip: refacto and start creating custom resolver * feat: findMany & findUnique of a custom entity * feat: wip pagination * feat: initial metadata migration * feat: universal findAll with pagination * fix: clean small stuff in pagination * fix: test * fix: miss file * feat: rename custom into universal * feat: create metadata schema in default database --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
56
server/src/tenant/universal/universal.resolver.ts
Normal file
56
server/src/tenant/universal/universal.resolver.ts
Normal file
@ -0,0 +1,56 @@
|
||||
import { Args, Query, Resolver } from '@nestjs/graphql';
|
||||
import { UseGuards } from '@nestjs/common';
|
||||
|
||||
import { Workspace } from '@prisma/client';
|
||||
|
||||
import { JwtAuthGuard } from 'src/guards/jwt.auth.guard';
|
||||
import { AuthWorkspace } from 'src/decorators/auth-workspace.decorator';
|
||||
|
||||
import { UniversalEntity, PaginatedUniversalEntity } from './universal.entity';
|
||||
import { UniversalService } from './universal.service';
|
||||
|
||||
import { FindManyUniversalArgs } from './args/find-many-universal.args';
|
||||
import { FindUniqueUniversalArgs } from './args/find-unique-universal.args';
|
||||
import { UpdateOneCustomArgs } from './args/update-one-custom.args';
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Resolver(() => UniversalEntity)
|
||||
export class UniversalResolver {
|
||||
constructor(private readonly customService: UniversalService) {}
|
||||
|
||||
@Query(() => PaginatedUniversalEntity)
|
||||
findMany(
|
||||
@Args() args: FindManyUniversalArgs,
|
||||
@AuthWorkspace() workspace: Workspace,
|
||||
): Promise<PaginatedUniversalEntity> {
|
||||
return this.customService.findManyUniversal(args, workspace);
|
||||
}
|
||||
|
||||
@Query(() => UniversalEntity)
|
||||
findUnique(
|
||||
@Args() args: FindUniqueUniversalArgs,
|
||||
@AuthWorkspace() workspace: Workspace,
|
||||
): Promise<UniversalEntity | undefined> {
|
||||
return this.customService.findUniqueUniversal(args, workspace);
|
||||
}
|
||||
|
||||
@Query(() => UniversalEntity)
|
||||
updateOneCustom(@Args() args: UpdateOneCustomArgs): UniversalEntity {
|
||||
return {
|
||||
id: 'exampleId',
|
||||
data: {},
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
};
|
||||
}
|
||||
|
||||
@Query(() => UniversalEntity)
|
||||
deleteOneCustom(@Args() args: UpdateOneCustomArgs): UniversalEntity {
|
||||
return {
|
||||
id: 'exampleId',
|
||||
data: {},
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user