Skip to content

Commit

Permalink
Merge pull request #43 from raychz/statusPage
Browse files Browse the repository at this point in the history
Status page
  • Loading branch information
raychz authored Feb 2, 2020
2 parents bce126c + 2589d85 commit 531d46f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/enums/ticket-updates.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ export enum TicketUpdates {
/** Used to bundle multiple messages together */
MULTIPLE_UPDATES = 'MULTIPLE_UPDATES',

// Ticket-related updates
/** The stats of the ticket changed and should be represented as such */
TICKET_UPDATED = 'TICKET_UPDATED',

// TicketUser-related updates
/** A new user should be pushed to the client's representation of ticket users. */
TICKET_USER_ADDED = 'TICKET_USER_ADDED',
Expand Down
2 changes: 1 addition & 1 deletion src/services/ticket-payment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class TicketPaymentService {
tax: responseTicket.totals.tax,
tips: responseTicket.totals.tips,
total: responseTicket.totals.total,
});
}, details.ticket.id!);
} else {
Logger.error(response, 'Error occurred while parsing the Omnivore response');

Expand Down
11 changes: 7 additions & 4 deletions src/services/ticket-total.service.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { Injectable } from '@nestjs/common';
import { getRepository } from 'typeorm';
import { TicketTotal } from '@tabify/entities';
import { SpreedlyService, TicketService } from '@tabify/services';
import { SpreedlyService, TicketService, AblyService } from '@tabify/services';
import { TicketUpdates } from '../enums';

@Injectable()
export class TicketTotalService {
constructor() { }
constructor(private readonly ablyService: AblyService) { }

async updateTicketTotals(ticketTotal: TicketTotal) {
async updateTicketTotals(ticketTotal: TicketTotal, ticketId: number) {
const ticketTotalRepo = await getRepository(TicketTotal);
return await ticketTotalRepo.save(ticketTotal);
const updatedTicketTotal = await ticketTotalRepo.save(ticketTotal);
await this.ablyService.publish(TicketUpdates.TICKET_TOTALS_UPDATED, updatedTicketTotal, ticketId.toString());
return updatedTicketTotal;
}

async getTicketTotals(ticketId: number, relations: string[] = []) {
Expand Down
4 changes: 2 additions & 2 deletions src/services/ticket-user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export class TicketUserService {
tax: totals.tax,
tips: totals.tips,
total: totals.total,
});
}, ticketId);
Logger.log(response, 'The updated ticket with discount');
} catch (e) {
Logger.error(e, undefined, 'An error occurred while adding the discount ticket item');
Expand Down Expand Up @@ -290,7 +290,7 @@ export class TicketUserService {

if (sendNotification) {
const messages: { name: string, data: any }[] = [
{ name: TicketUpdates.TICKET_USERS_UPDATED, data: updatedTicketUsers }
{ name: TicketUpdates.TICKET_USERS_UPDATED, data: updatedTicketUsers },
];
if (ticketTotal) {
messages.push({ name: TicketUpdates.TICKET_TOTALS_UPDATED, data: ticketTotal });
Expand Down
7 changes: 5 additions & 2 deletions src/services/ticket.service.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Injectable, Logger, BadRequestException, NotFoundException, InternalServerErrorException } from '@nestjs/common';
import { getRepository, getConnection, FindOneOptions, FindConditions, InsertResult, MoreThanOrEqual } from 'typeorm';
import { auth } from 'firebase-admin';
import { FirebaseService, OmnivoreService, UserService, SMSService, ServerService } from '@tabify/services';
import { FirebaseService, OmnivoreService, UserService, SMSService, ServerService, AblyService } from '@tabify/services';
import {
Ticket as TicketEntity,
TicketItem as TicketItemEntity,
User as UserEntity,
TicketItem,
TicketTotal,
} from '@tabify/entities';
import { TicketStatus } from '../enums';
import { TicketStatus, TicketUpdates } from '../enums';

@Injectable()
export class TicketService {
Expand All @@ -18,6 +18,7 @@ export class TicketService {
private readonly messageService: SMSService,
private readonly serverService: ServerService,
private readonly userService: UserService,
private readonly ablyService: AblyService,
) { }

/**
Expand Down Expand Up @@ -153,6 +154,8 @@ export class TicketService {

await this.serverService.sendTicketCloseSMSToServer(ticketId);

await this.ablyService.publish(TicketUpdates.TICKET_UPDATED, {id: ticketId, ticket_status: TicketStatus.CLOSED}, ticketId.toString());

return res;
}

Expand Down

0 comments on commit 531d46f

Please sign in to comment.