refactor: branches and warehouses to nestjs

This commit is contained in:
Ahmed Bouhuolia
2024-12-21 00:10:09 +02:00
parent dc52f784b6
commit cb8fd68d46
126 changed files with 5419 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
import { Inject } from '@nestjs/common';
import { Injectable } from '@nestjs/common';
import { Branch } from '../models/Branch.model';
@Injectable()
export class GetBranchService {
constructor(
@Inject(Branch.name)
private readonly branch: typeof Branch,
) {}
/**
* Retrieves the given branch details.
* @param {number} branchId
* @returns {Promise<IBranch>}
*/
public getBranch = async (branchId: number): Promise<Branch> => {
const branch = await this.branch
.query()
.findById(branchId)
.throwIfNotFound();
return branch;
};
}

View File

@@ -0,0 +1,20 @@
import { Inject, Injectable } from '@nestjs/common';
import { Branch } from '../models/Branch.model';
@Injectable()
export class GetBranchesService {
constructor(
@Inject(Branch.name)
private readonly branch: typeof Branch,
) {}
/**
* Retrieves branches list.
* @returns
*/
public getBranches = async () => {
const branches = await this.branch.query().orderBy('name', 'DESC');
return branches;
};
}