import 'reflect-metadata' ; import { Get , Post , Put , Delete , Body , JsonController , Authorized , Res , Req , QueryParam , Param } from 'routing-controllers' ; import { OrderStatus } from '../models/OrderStatus' ; import { OrderStatusService } from '../services/OrderStatusService' ; import { CreateOrderStatus } from './requests/CreateOrderStatusRequest' ; @ JsonController ( '/order-status' ) export class OrderStatusController { constructor ( private orderStatusService ) { } api apiGroup apiParam apiParam apiParam apiHeader apiParamExample apiSuccessExample apiSampleRequest apiErrorExample @ Post ( '/create-order-status' ) @ Authorized ( ) public async createOrderStatus ( @ Body ( { validate : true } ) orderStatusParam , @ Res ( ) response ) { const newOrderStatus = new OrderStatus ( ) ; newOrderStatus . name = orderStatusParam . name ; newOrderStatus . colorCode = orderStatusParam . colorCode ; newOrderStatus . isActive = orderStatusParam . status ; const orderStatusSave = await this . orderStatusService . create ( newOrderStatus ) ; if ( orderStatusSave !== undefined ) { const successResponse = { status : 1 , message : 'successfully created a new order status.' , data : orderStatusSave , } ; return response . status ( 200 ) . send ( successResponse ) ; } else { const errorResponse = { status : 0 , message : 'unable to create OrderStatus' , } ; return response . status ( 400 ) . send ( errorResponse ) ; } } api apiGroup apiHeader apiParam apiParam apiParam apiParamExample apiSuccessExample apiSampleRequest apiErrorExample @ Put ( '/update-order-status/:id' ) @ Authorized ( ) public async updateOrderStatus ( @ Body ( { validate : true } ) orderStatusParams , @ Param ( 'id' ) id , @ Res ( ) response , @ Req ( ) request ) { const orderStatus = await this . orderStatusService . findOne ( { where : { orderStatusId : id , } , } ) ; if ( ! orderStatus ) { const errorResponse = { status : 0 , message : 'Invalid orderStatusId' , } ; return response . status ( 400 ) . send ( errorResponse ) ; } orderStatus . name = orderStatusParams . name ; orderStatus . colorCode = orderStatusParams . colorCode ; orderStatus . isActive = orderStatusParams . status ; const orderStatusSave = await this . orderStatusService . create ( orderStatus ) ; console . log ( 'orderStatus' + orderStatusSave ) ; if ( orderStatusSave !== undefined ) { const successResponse = { status : 1 , message : 'Successfully updated the order status.' , data : orderStatusSave , } ; return response . status ( 200 ) . send ( successResponse ) ; } else { const errorResponse = { status : 1 , message : 'unable to update OrderStatus.' , } ; return response . status ( 400 ) . send ( errorResponse ) ; } } api apiGroup apiHeader apiParam apiParam apiParam apiParam apiParam apiSuccessExample apiSampleRequest apiErrorExample @ Get ( '/order-status-list' ) @ Authorized ( ) public async orderStatusList ( @ QueryParam ( 'limit' ) limit , @ QueryParam ( 'offset' ) offset , @ QueryParam ( 'keyword' ) keyword , @ QueryParam ( 'status' ) status , @ QueryParam ( 'count' ) count , @ Res ( ) response ) { const select = [ 'orderStatusId' , 'name' , 'colorCode' , 'isActive' ] ; const search = [ { name : 'name' , op : 'like' , value : keyword , } , { name : 'isActive' , op : 'like' , value : status , } , ] ; const WhereConditions = [ ] ; const orderStatusList = await this . orderStatusService . list ( limit , offset , select , search , WhereConditions , count ) ; if ( orderStatusList ) { const successResponse = { status : 1 , message : 'Successfully got the complete order status list.' , data : orderStatusList , } ; return response . status ( 200 ) . send ( successResponse ) ; } else { const errorResponse = { status : 0 , message : 'unable to get OrderStatus.' , } ; return response . status ( 400 ) . send ( errorResponse ) ; } } api apiGroup apiHeader apiParamExample apiSuccessExample apiSampleRequest apiErrorExample @ Delete ( '/delete-order-status/:id' ) @ Authorized ( ) public async deleteOrderStatus ( @ Param ( 'id' ) id , @ Res ( ) response , @ Req ( ) request ) { const orderStatus = await this . orderStatusService . findOne ( { where : { orderStatusId : id , } , } ) ; if ( ! orderStatus ) { const errorResponse = { status : 0 , message : 'Invalid orderStatusId.' , } ; return response . status ( 400 ) . send ( errorResponse ) ; } const deleteOrderStatus = await this . orderStatusService . delete ( orderStatus ) ; if ( deleteOrderStatus ) { const successResponse = { status : 1 , message : 'Successfully deleted the order status.' , } ; return response . status ( 200 ) . send ( successResponse ) ; } else { const errorResponse = { status : 0 , message : 'unable to delete orderStatus.' , } ; return response . status ( 400 ) . send ( errorResponse ) ; } } }