import 'reflect-metadata' ; import { Get , Post , Put , Delete , Body , JsonController , Authorized , Res , Req , QueryParam , Param } from 'routing-controllers' ; import { CreateStockStatus } from './requests/CreateStockStatusRequest' ; import { StockStatus } from '../models/stockStatus' ; import { StockStatusService } from '../services/stockStatusService' ; @ JsonController ( '/stock-status' ) export class StockStatusController { constructor ( private stockStatusService ) { } api apiGroup apiParam apiParam apiHeader apiParamExample apiSuccessExample apiSampleRequest apiErrorExample @ Post ( '/create-stock-status' ) @ Authorized ( ) public async createStockStatus ( @ Body ( { validate : true } ) stockStatusParam , @ Res ( ) response ) { const newStockStatus = new StockStatus ( ) ; newStockStatus . name = stockStatusParam . name ; newStockStatus . isActive = stockStatusParam . status ; const StockStatusSave = await this . stockStatusService . create ( newStockStatus ) ; if ( StockStatusSave !== undefined ) { const successResponse = { status : 1 , message : 'Successfully created new StockStatus' , data : StockStatusSave , } ; return response . status ( 200 ) . send ( successResponse ) ; } else { const errorResponse = { status : 0 , message : 'unable to create StockStatus' , } ; return response . status ( 400 ) . send ( errorResponse ) ; } } api apiGroup apiHeader apiParam apiParam apiParamExample apiSuccessExample apiSampleRequest apiErrorExample @ Put ( '/update-stock-status/:id' ) @ Authorized ( ) public async updateStockStatus ( @ Param ( 'id' ) id , @ Body ( { validate : true } ) stockStatusParams , @ Res ( ) response , @ Req ( ) request ) { const stockStatus = await this . stockStatusService . findOne ( { where : { stockStatusId : id , } , } ) ; if ( ! stockStatus ) { const errorResponse = { status : 0 , message : 'Invalid stockStatus' , } ; return response . status ( 400 ) . send ( errorResponse ) ; } stockStatus . name = stockStatusParams . name ; stockStatus . isActive = stockStatusParams . status ; const stockStatusSave = await this . stockStatusService . create ( stockStatus ) ; if ( stockStatusSave !== undefined ) { const successResponse = { status : 1 , message : 'Successfully updated stockStatus' , data : stockStatusSave , } ; return response . status ( 200 ) . send ( successResponse ) ; } else { const errorResponse = { status : 1 , message : 'unable to update stockStatus' , } ; return response . status ( 400 ) . send ( errorResponse ) ; } } api apiGroup apiHeader apiParam apiParam apiParam apiParam apiParam apiSuccessExample apiSampleRequest apiErrorExample @ Get ( '/stock-status-list' ) @ Authorized ( ) public async stockStatusList ( @ QueryParam ( 'limit' ) limit , @ QueryParam ( 'offset' ) offset , @ QueryParam ( 'keyword' ) keyword , @ QueryParam ( 'status' ) status , @ QueryParam ( 'count' ) count , @ Res ( ) response ) { console . log ( keyword ) ; const select = [ 'stockStatusId' , 'name' , 'isActive' ] ; const search = [ { name : 'name' , op : 'like' , value : keyword , } , { name : 'isActive' , op : 'like' , value : status , } , ] ; const WhereConditions = [ ] ; const stockStatusList = await this . stockStatusService . list ( limit , offset , select , search , WhereConditions , count ) ; if ( stockStatusList ) { const successResponse = { status : 1 , message : 'Successfully got all stockStatus List' , data : stockStatusList , } ; return response . status ( 200 ) . send ( successResponse ) ; } else { const errorResponse = { status : 0 , message : 'unable to get stockStatusList' , } ; return response . status ( 400 ) . send ( errorResponse ) ; } } api apiGroup apiHeader apiParamExample apiSuccessExample apiSampleRequest apiErrorExample @ Delete ( '/delete-stock-status/:id' ) @ Authorized ( ) public async deleteStockStatus ( @ Param ( 'id' ) id , @ Res ( ) response , @ Req ( ) request ) { const stockStatus = await this . stockStatusService . findOne ( { where : { stockStatusId : id , } , } ) ; if ( ! stockStatus ) { const errorResponse = { status : 0 , message : 'Invalid stockStatusId' , } ; return response . status ( 400 ) . send ( errorResponse ) ; } const deleteStockStatus = await this . stockStatusService . delete ( stockStatus ) ; if ( deleteStockStatus ) { const successResponse = { status : 1 , message : 'Successfully deleted stockStatus' , } ; return response . status ( 200 ) . send ( successResponse ) ; } else { const errorResponse = { status : 0 , message : 'unable to delete stockStatus' , } ; return response . status ( 400 ) . send ( errorResponse ) ; } } }