Created
December 21, 2022 15:02
-
-
Save iconifyit/a0dea5a452258ed9362224764f42a849 to your computer and use it in GitHub Desktop.
Medusa ProductRepository override
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ProductRepository as MedusaProductRepository } from "@medusajs/medusa/dist/repositories/product"; | |
import { Repository as MedusaRepository, Utils } from "medusa-extender"; | |
import { EntityRepository, In } from "typeorm"; | |
import { Product } from "./product.entity"; | |
@MedusaRepository({ override: MedusaProductRepository }) | |
@EntityRepository(Product) | |
export default class ProductRepository extends Utils.repositoryMixin<Product, MedusaProductRepository>(MedusaProductRepository) { | |
public async bulkAddToSet( | |
productIds: string[], | |
setId: string | |
): Promise<Product[]> { | |
await this.createQueryBuilder() | |
.update(Product) | |
.set({ set_id: setId }) | |
.where({ id: In(productIds) }) | |
.execute() | |
return this.findByIds(productIds) | |
} | |
public async bulkRemoveFromSet( | |
productIds: string[], | |
setId: string | |
): Promise<Product[]> { | |
await this.createQueryBuilder() | |
.update(Product) | |
.set({ set_id: null }) | |
.where({ id: In(productIds), set_id: setId }) | |
.execute() | |
return this.findByIds(productIds) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment