Skip to content

Instantly share code, notes, and snippets.

@iconifyit
Created December 21, 2022 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iconifyit/a0dea5a452258ed9362224764f42a849 to your computer and use it in GitHub Desktop.
Save iconifyit/a0dea5a452258ed9362224764f42a849 to your computer and use it in GitHub Desktop.
Medusa ProductRepository override
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