@@ -131,9 +131,8 @@ export class InvoiceController {
131131 discount : body . discount ,
132132 } ;
133133
134- await this . invoiceService . createInvoice ( invoiceRequest ) ;
135- const invoiceList = await this . invoiceService . getInvoiceList ( userId , { page : '1' , limit : '20' } ) ;
136- return res . status ( HttpStatus . OK ) . json ( invoiceList ) ;
134+ const invoice = await this . invoiceService . createInvoice ( invoiceRequest ) ;
135+ return res . status ( HttpStatus . OK ) . json ( invoice . data . insert_invoice . returning [ 0 ] ) ;
137136 } catch ( e ) {
138137 if ( file && file . path ) fs . unlinkSync ( file . path ) ;
139138 if ( newFileLogo ) fs . unlinkSync ( newFileLogo ) ;
@@ -147,7 +146,7 @@ export class InvoiceController {
147146 async getInvoices (
148147 @Headers ( ) headers : any ,
149148 @Response ( ) res : any ,
150- @Query ( ) query : { page ?: string ; limit ?: string }
149+ @Query ( ) query : { page ?: string ; limit ?: string ; search ?: string }
151150 ) {
152151 const userId : string = await this . authService . getVerifiedUserId ( headers . authorization ) ;
153152 if ( ! userId ) {
@@ -170,6 +169,26 @@ export class InvoiceController {
170169 }
171170 }
172171
172+ @Get ( 'total' )
173+ @UseGuards ( AuthGuard ( ) )
174+ async getTotal ( @Headers ( ) headers : any , @Response ( ) res : any , @Query ( ) query : { search ?: string } ) {
175+ let { search } = query ;
176+ const userId : string = await this . authService . getVerifiedUserId ( headers . authorization ) ;
177+
178+ if ( ! userId ) {
179+ throw new UnauthorizedException ( ) ;
180+ }
181+
182+ try {
183+ const invoiceList = await this . invoiceService . getGrandTotal ( userId , search ) ;
184+
185+ return res . status ( HttpStatus . OK ) . json ( invoiceList ) ;
186+ } catch ( err ) {
187+ const error : AxiosError = err ;
188+ return res . status ( HttpStatus . BAD_REQUEST ) . json ( error . response ? error . response . data . errors : error ) ;
189+ }
190+ }
191+
173192 @Get ( ':id/generatePDF' )
174193 async generatePDF ( @Response ( ) res : any , @Param ( ) param : { id : string } ) {
175194 let invoice : Invoice = null ;
@@ -305,14 +324,12 @@ export class InvoiceController {
305324 } ) ;
306325
307326 try {
308- await this . invoiceService . updateInvoice ( invoiceData ) ;
327+ const invoiceId = await this . invoiceService . updateInvoice ( invoiceData ) ;
309328 if ( file && file . path && invoice . logo && fs . existsSync ( invoice . logo ) ) {
310329 fs . unlinkSync ( invoice . logo ) ;
311330 }
312331
313- const invoiceList = await this . invoiceService . getInvoiceList ( userId , { page : '1' , limit : '20' } ) ;
314-
315- return res . status ( HttpStatus . OK ) . json ( invoiceList ) ;
332+ return res . status ( HttpStatus . OK ) . json ( invoiceId . data . update_invoice_vendor . returning [ 0 ] ) ;
316333 } catch ( err ) {
317334 if ( file && file . path ) fs . unlinkSync ( file . path ) ;
318335 const error : AxiosError = err ;
@@ -338,9 +355,9 @@ export class InvoiceController {
338355
339356 try {
340357 const paymentStatus : boolean = body . paymentStatus || false ;
341- await this . invoiceService . updatePaymentStatusInvoice ( userId , param . id , paymentStatus ) ;
342- const invoiceList = await this . invoiceService . getInvoiceList ( userId , { page : '1' , limit : '10' } ) ;
343- return res . status ( HttpStatus . OK ) . json ( invoiceList ) ;
358+
359+ const invoiceId = await this . invoiceService . updatePaymentStatusInvoice ( userId , param . id , paymentStatus ) ;
360+ return res . status ( HttpStatus . OK ) . json ( invoiceId ) ;
344361 } catch ( err ) {
345362 const error : AxiosError = err ;
346363 return res . status ( HttpStatus . BAD_REQUEST ) . json ( error . response ? error . response . data . errors : error ) ;
@@ -374,8 +391,8 @@ export class InvoiceController {
374391 const delInvoice : any = await this . invoiceService . deleteInvoice ( userId , param . id ) ;
375392 if ( delInvoice . logo && fs . existsSync ( delInvoice . logo ) ) fs . unlinkSync ( delInvoice . logo ) ;
376393
377- const invoiceList = await this . invoiceService . getInvoiceList ( userId , { page : '1' , limit : '10' } ) ;
378- return res . status ( HttpStatus . OK ) . json ( invoiceList ) ;
394+ const { invoice_vendor_id , logo , ... invoiceId } = delInvoice ;
395+ return res . status ( HttpStatus . OK ) . json ( invoiceId ) ;
379396 } catch ( err ) {
380397 const error : AxiosError = err ;
381398 return res . status ( HttpStatus . BAD_REQUEST ) . json ( error . response ? error . response . data . errors : error ) ;
0 commit comments