52 lines
3.4 KiB
TypeScript
52 lines
3.4 KiB
TypeScript
import { Resolver, Query, FieldResolver, Root, Arg, Mutation, Ctx, Args, Authorized, ResolverInterface } from 'type-graphql';
|
|
|
|
import PromoModel, { PromoArgs, NewPromoInput, EditPromoInput } from '@services/module-payments/functions/promos/promo.model';
|
|
import { ApolloContext } from '@seed/interfaces/context';
|
|
import { createBaseResolver } from '@seed/graphql/baseResolvers/BaseResolver';
|
|
import { AccountTypeEnum } from '@src/accounts/account.components';
|
|
import { getOneGeneric, getManyGenericWithArgs, addOneGeneric, editOneGeneric, deleteOneGeneric } from '@seed/graphql/BaseService';
|
|
import { onCreate, onUpdate } from './promo.model';
|
|
|
|
const PromoBaseResolver = createBaseResolver('promos', PromoModel, PromoArgs, NewPromoInput, EditPromoInput, [AccountTypeEnum.admin]);
|
|
|
|
@Resolver(PromoModel)
|
|
export default class PromoAdminResolver extends PromoBaseResolver {
|
|
/*
|
|
██████╗ ██╗ ██╗███████╗██████╗ ██╗ ██╗
|
|
██╔═══██╗██║ ██║██╔════╝██╔══██╗╚██╗ ██╔╝
|
|
██║ ██║██║ ██║█████╗ ██████╔╝ ╚████╔╝
|
|
██║▄▄ ██║██║ ██║██╔══╝ ██╔══██╗ ╚██╔╝
|
|
╚██████╔╝╚██████╔╝███████╗██║ ██║ ██║
|
|
╚══▀▀═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═╝
|
|
*/
|
|
/*
|
|
███╗ ███╗██╗ ██╗████████╗ █████╗ ████████╗ ██████╗ ██████╗ ███████╗
|
|
████╗ ████║██║ ██║╚══██╔══╝██╔══██╗╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝
|
|
██╔████╔██║██║ ██║ ██║ ███████║ ██║ ██║ ██║██████╔╝███████╗
|
|
██║╚██╔╝██║██║ ██║ ██║ ██╔══██║ ██║ ██║ ██║██╔══██╗╚════██║
|
|
██║ ╚═╝ ██║╚██████╔╝ ██║ ██║ ██║ ██║ ╚██████╔╝██║ ██║███████║
|
|
╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝
|
|
*/
|
|
@Mutation(() => PromoModel)
|
|
@Authorized([AccountTypeEnum.admin])
|
|
async addOne(@Arg('input') input: NewPromoInput, @Ctx() ctx: ApolloContext): Promise<PromoModel> {
|
|
const model = new PromoModel();
|
|
const toSave = {
|
|
...input,
|
|
usage: 0,
|
|
};
|
|
await onCreate(input, ctx);
|
|
|
|
return addOneGeneric(model, toSave, ctx);
|
|
}
|
|
|
|
@Mutation(() => PromoModel)
|
|
@Authorized([AccountTypeEnum.admin])
|
|
async editOne(@Arg('id') id: string, @Arg('input') input: EditPromoInput, @Ctx() ctx: ApolloContext): Promise<PromoModel> {
|
|
const model = new PromoModel();
|
|
await onUpdate(input, ctx);
|
|
|
|
return editOneGeneric(model, id, input, ctx);
|
|
}
|
|
}
|