@ -15,12 +15,17 @@ import { relationAbilityChecker } from 'src/ability/ability.util';
|
|||||||
import { ViewFieldWhereInput } from 'src/core/@generated/view-field/view-field-where.input';
|
import { ViewFieldWhereInput } from 'src/core/@generated/view-field/view-field-where.input';
|
||||||
import { PrismaService } from 'src/database/prisma.service';
|
import { PrismaService } from 'src/database/prisma.service';
|
||||||
import { assert } from 'src/utils/assert';
|
import { assert } from 'src/utils/assert';
|
||||||
|
import { ViewFieldWhereUniqueInput } from 'src/core/@generated/view-field/view-field-where-unique.input';
|
||||||
|
|
||||||
class ViewFieldArgs {
|
class ViewFieldArgs {
|
||||||
where?: ViewFieldWhereInput;
|
where?: ViewFieldWhereInput;
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isViewFieldWhereUniqueInput = (
|
||||||
|
input: ViewFieldWhereInput | ViewFieldWhereUniqueInput,
|
||||||
|
): input is ViewFieldWhereUniqueInput => 'viewId_key' in input;
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ReadViewFieldAbilityHandler implements IAbilityHandler {
|
export class ReadViewFieldAbilityHandler implements IAbilityHandler {
|
||||||
handle(ability: AppAbility) {
|
handle(ability: AppAbility) {
|
||||||
@ -59,7 +64,10 @@ export class UpdateViewFieldAbilityHandler implements IAbilityHandler {
|
|||||||
const gqlContext = GqlExecutionContext.create(context);
|
const gqlContext = GqlExecutionContext.create(context);
|
||||||
const args = gqlContext.getArgs<ViewFieldArgs>();
|
const args = gqlContext.getArgs<ViewFieldArgs>();
|
||||||
const viewField = await this.prismaService.client.viewField.findFirst({
|
const viewField = await this.prismaService.client.viewField.findFirst({
|
||||||
where: args.where,
|
where:
|
||||||
|
args.where && isViewFieldWhereUniqueInput(args.where)
|
||||||
|
? args.where.viewId_key
|
||||||
|
: args.where,
|
||||||
});
|
});
|
||||||
assert(viewField, '', NotFoundException);
|
assert(viewField, '', NotFoundException);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user