Your IP : 216.73.217.95


Current Path : /proc/thread-self/root/home/deltalab/PMS/logistic-backend/src/models/carriers/
Upload File :
Current File : //proc/thread-self/root/home/deltalab/PMS/logistic-backend/src/models/carriers/carrier.service.ts

import { Model } from 'mongoose';
import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Carrier, CarrierDocument } from './carrier.schema';

@Injectable()
export class CarrierService {
  constructor(
    @InjectModel(Carrier.name)
    private carrierModel: Model<CarrierDocument>,
  ) {}

  async create(carrier: Carrier): Promise<Carrier> {
    const createdCat = new this.carrierModel(carrier);
    return createdCat.save();
  }

  async delete(id: string): Promise<Carrier> {
    return await this.carrierModel.findByIdAndRemove(id);
  }

  async update(id: string, carrier: Carrier): Promise<Carrier> {
    return await this.carrierModel.findByIdAndUpdate(id, carrier, {
      new: true,
    });
  }

  async readAll(): Promise<Carrier[]> {
    return this.carrierModel.find().exec();
  }

  async readById(id: string): Promise<Carrier> {
    return await this.carrierModel.findById(id).exec();
  }
}