Skip to content

Commit 80ea614

Browse files
authored
Merge pull request #88 from wbbly/dev
UPDATE | bug fixes
2 parents b3b580f + 51101c6 commit 80ea614

24 files changed

Lines changed: 1007 additions & 63 deletions

app/package-lock.json

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"apollo-server-express": "2.14.2",
3737
"axios": "0.19.0",
3838
"bcrypt": "5.0.0",
39+
"billwerk": "2.1.2",
3940
"crypto": "1.0.1",
4041
"dotenv": "7.0.0",
4142
"fs-extra": "7.0.1",

app/src/app.module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import { ClientModule } from './client/client.module';
1919
import { SocialModule } from './social/social.module';
2020
import { TechnologyModule } from './technology/technology.module';
2121
import { InvoiceModule } from './invoice/invoice.module';
22+
import { PaymentModule } from './payment/payment.module';
23+
import { SubscriptionModule } from './subscription/subscription.module';
2224

2325
@Module({
2426
imports: [
@@ -39,6 +41,8 @@ import { InvoiceModule } from './invoice/invoice.module';
3941
SocialModule,
4042
TechnologyModule,
4143
InvoiceModule,
44+
PaymentModule,
45+
SubscriptionModule,
4246
],
4347
controllers: [AppController],
4448
providers: [AppService],

app/src/invoice/invoice.controller.ts

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)