Skip to content

Commit

Permalink
service ad resolver for getting a single product image by its ID
Browse files Browse the repository at this point in the history
  • Loading branch information
Shukazuby committed Feb 11, 2025
1 parent 5db1598 commit 49acfdb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/backend/src/core/graphql/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ input ProductImageDTO {
}

type Query {
ProductImage(id: String!): ProductImage
ProductImages: [ProductImage!]!
categories: [Category!]!
category(id: String!): Category
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ export class ProductImageResolver {
return await this.productImageService.getAllProductImages();
}

@Query(() => ProductImage, { nullable: true })
async ProductImage(@Args("id") id: string) {
return await this.productImageService.getAProductImage(id);
}

}
11 changes: 11 additions & 0 deletions apps/backend/src/modules/product-image/product-image.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,16 @@ export class ProductImageService {
}
return productImages
}

async getAProductImage(id: string) {
const productImage = await this.prisma.productImage.findUnique({ where: { id } });

if (!productImage) {
throw new Error(`Product image not found.`);
}

return productImage;

}

}

0 comments on commit 49acfdb

Please sign in to comment.