1- import { Arg , Ctx , Int , Mutation , Query , Resolver } from "type-graphql" ;
1+ import { Arg , Ctx , Int , Mutation , Query , Resolver , UseMiddleware } from "type-graphql" ;
22import { Gift } from "../entities/Gift" ;
33import List from "../entities/List" ;
44import User from "../entities/User" ;
55// biome-ignore lint/style/useImportType: bypass biome linting
66import { AddGiftInput } from "../inputs/AddGiftInput" ;
77// biome-ignore lint/style/useImportType: bypass biome linting
88import { UpdateGiftInput } from "../inputs/UpdateGiftInput" ;
9+ import { RoleMiddleware } from "../middleware/RoleMiddleware" ;
910import type { ContextType } from "../types/context" ;
1011import { getOrCreateUserWishlist } from "../utils/getOrCreateUserWishlist" ;
1112
1213@Resolver ( )
1314export default class MyWishlistResolver {
1415 @Query ( ( ) => [ Gift ] )
16+ @UseMiddleware ( RoleMiddleware ( ) )
1517 async myWishlistItems ( @Ctx ( ) ctx : ContextType ) : Promise < Gift [ ] > {
1618 if ( ! ctx . user ) throw new Error ( "Utilisateur non connecté" ) ;
1719
@@ -25,6 +27,7 @@ export default class MyWishlistResolver {
2527 }
2628
2729 @Mutation ( ( ) => Gift )
30+ @UseMiddleware ( RoleMiddleware ( ) )
2831 async addGift ( @Arg ( "data" ) data : AddGiftInput , @Ctx ( ) ctx : ContextType ) : Promise < Gift > {
2932 if ( ! ctx . user ) throw new Error ( "Utilisateur non connecté" ) ;
3033
@@ -60,6 +63,7 @@ export default class MyWishlistResolver {
6063 }
6164
6265 @Mutation ( ( ) => Gift )
66+ @UseMiddleware ( RoleMiddleware ( ) )
6367 async updateGift (
6468 @Arg ( "id" , ( ) => Int ) id : number ,
6569 @Arg ( "data" ) data : UpdateGiftInput ,
@@ -81,6 +85,7 @@ export default class MyWishlistResolver {
8185 return gift ;
8286 }
8387
88+ @UseMiddleware ( RoleMiddleware ( ) )
8489 @Mutation ( ( ) => Int )
8590 async deleteGift ( @Arg ( "id" , ( ) => Int ) id : number , @Ctx ( ) ctx : ContextType ) : Promise < number > {
8691 if ( ! ctx . user ) throw new Error ( "Utilisateur non connecté" ) ;
0 commit comments