feat: add change status partner endpoint
This commit is contained in:
parent
6b1352e671
commit
04fd5c571f
|
@ -1,4 +1,10 @@
|
||||||
import { forwardRef, HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common';
|
import {
|
||||||
|
forwardRef,
|
||||||
|
HttpException,
|
||||||
|
HttpStatus,
|
||||||
|
Inject,
|
||||||
|
Injectable,
|
||||||
|
} from '@nestjs/common';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { Connection, Not, Repository } from 'typeorm';
|
import { Connection, Not, Repository } from 'typeorm';
|
||||||
import { CoaService } from '../../transaction/coa.service';
|
import { CoaService } from '../../transaction/coa.service';
|
||||||
|
@ -108,6 +114,24 @@ export class PartnerService {
|
||||||
return partnerData;
|
return partnerData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setStatus = async (id: string, type: string) => {
|
||||||
|
const partnerData = await this.partnerRepository.findOne({
|
||||||
|
id: id,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (type === 'active') {
|
||||||
|
partnerData.status = true;
|
||||||
|
} else {
|
||||||
|
partnerData.status = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.connection.transaction(async (manager) => {
|
||||||
|
await manager.update(Partner, { id: id }, partnerData);
|
||||||
|
});
|
||||||
|
|
||||||
|
return partnerData;
|
||||||
|
};
|
||||||
|
|
||||||
findAllPartner(page) {
|
findAllPartner(page) {
|
||||||
return this.partnerRepository.findAndCount({
|
return this.partnerRepository.findAndCount({
|
||||||
skip: page * 10,
|
skip: page * 10,
|
||||||
|
|
|
@ -62,6 +62,18 @@ export class UsersController {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get('partner/:id/:type')
|
||||||
|
async setStatusPartner(
|
||||||
|
@Param('id', ParseUUIDPipe) id: string,
|
||||||
|
@Param('type') type: string,
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
data: await this.partnerService.setStatus(id, type),
|
||||||
|
statusCode: HttpStatus.CREATED,
|
||||||
|
message: 'success',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@Put('partner/:id')
|
@Put('partner/:id')
|
||||||
async updatePartner(
|
async updatePartner(
|
||||||
@Param('id', ParseUUIDPipe) id: string,
|
@Param('id', ParseUUIDPipe) id: string,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user