pos-be/src/modules/item-related/item/data/services/item-data.service.ts

35 lines
1.1 KiB
TypeScript

import { Injectable } from '@nestjs/common';
import { BaseDataService } from 'src/core/modules/data/service/base-data.service';
import { ItemEntity } from '../../domain/entities/item.entity';
import { InjectRepository } from '@nestjs/typeorm';
import { ItemModel } from '../models/item.model';
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
import { Repository } from 'typeorm';
import { ItemRateModel } from 'src/modules/item-related/item-rate/data/models/item-rate.model';
@Injectable()
export class ItemDataService extends BaseDataService<ItemEntity> {
constructor(
@InjectRepository(ItemModel, CONNECTION_NAME.DEFAULT)
private repo: Repository<ItemModel>,
@InjectRepository(ItemRateModel, CONNECTION_NAME.DEFAULT)
private repoItemRate: Repository<ItemRateModel>,
) {
super(repo);
}
async updateItemRatePrice(
oldPrice: number,
newPrice: number,
itemId: string,
): Promise<void> {
console.log({ oldPrice, newPrice, itemId });
this.repoItemRate.update(
{ item_id: itemId, price: oldPrice },
{ price: newPrice },
);
}
}