Skip to content

Commit

Permalink
Merge pull request #34 from deviate-team/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
TeetouchQQ authored Aug 9, 2023
2 parents 68f4e50 + 684a566 commit ec0450b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/common/enums/transaction-type.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export enum TransactionType {
Ticket = 'ticket',
Project = 'project',
Offer = 'share',
Carbon = "carbon"
Carbon = "carbon",
Donate = "donate"
}
11 changes: 10 additions & 1 deletion src/tickets/dto/booking-ticket.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsNotEmpty, IsNumber, IsEnum } from 'class-validator';
import { IsNotEmpty, IsNumber, IsEnum, isNotEmpty, isNumber } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import { TicketOption } from '@/common/enums/ticket-option.enum';
export class BookingTicketDto {
Expand All @@ -10,6 +10,15 @@ export class BookingTicketDto {
@IsNumber()
quantity: number;


@ApiProperty({
description: 'Donation',
example: 20,
})
@IsNotEmpty()
@IsNumber()
donation: number;

@ApiProperty({
description: 'Option',
example: TicketOption.Standard,
Expand Down
43 changes: 39 additions & 4 deletions src/tickets/tickets.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class TicketsService {
) {}

async create(createTicketDto: CreateTicketDto, user) {
console.log(user._id);
await this.ticketModel.create({
...createTicketDto,
provider: user._id,
Expand Down Expand Up @@ -102,9 +103,14 @@ export class TicketsService {
};
}




async book(id: string, bookingDto: BookingTicketDto, user) {
const ticketExists = await this.ticketModel.findById(id).exec();
const { quantity, option } = bookingDto;


const { quantity, option,donation } = bookingDto;

if (!ticketExists) {
throw new HttpException(
Expand All @@ -125,8 +131,26 @@ export class TicketsService {
400,
);
}

const providerExits = await this.userModel.findById(ticketExists.provider).exec();
const userExists = await this.userModel.findById(user._id).exec();
if (!userExists) {
throw new HttpException(
{
success: false,
message: 'User not found',
},
404,
);
}
if(!providerExits){
throw new HttpException(
{
success: false,
message: 'Provider not found',
},
404,
);
}
const ticketPrice =
option === 'standard'
? ticketExists.standard_price
Expand Down Expand Up @@ -183,7 +207,7 @@ export class TicketsService {
description: `Booked ${quantity} ticket(s)`,
status: 'success',
total_price:
option === 'standard' ? ticketPrice * quantity : ticketPrice * quantity,
option === 'standard' ? (ticketPrice * quantity)+donation : (ticketPrice * quantity)+donation,
});

// transaction of provider
Expand All @@ -199,7 +223,18 @@ export class TicketsService {
? ticketExists.standard_price * quantity
: ticketExists.business_price * quantity,
});


await this.transactionService.create({
type: 'donate',
user: updatedTicket.provider,
ticket: id,
quantity:1,
description: `Got ${quantity} RetailCC(s)`,
status: 'success',
total_price: donation*0.7
});
providerExits.retailCC += donation*0.7;
providerExits.save();
return {
...updatedTicket.toJSON(),
seat_booked: updatedTicket.seat_booked.length,
Expand Down

0 comments on commit ec0450b

Please sign in to comment.