Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backend: implement all schemas #17

Merged
merged 11 commits into from
Dec 21, 2024
Empty file removed backend/src/schemas/.gitkeep
Empty file.
28 changes: 28 additions & 0 deletions backend/src/schemas/booking.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Types } from 'mongoose';

@Schema({ timestamps: true })
export class Booking {
@Prop({ type: Types.ObjectId, ref: 'Event', required: true })
event: Types.ObjectId;

@Prop({ type: Types.ObjectId, ref: 'User', required: true })
user: Types.ObjectId;

@Prop({ required: true })
guestCount: number;

@Prop({ required: true })
bookingStatus: 'PENDING' | 'APPROVED' | 'CANCELLED';

@Prop({ type: Types.ObjectId, ref: 'Payment', required: true })
payment: Types.ObjectId;

@Prop({ required: true })
bookingDate: Date;

@Prop({ required: true })
organizedAt: string;
}

export const BookingSchema = SchemaFactory.createForClass(Booking);
12 changes: 12 additions & 0 deletions backend/src/schemas/category.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';

@Schema({ timestamps: true })
export class Category {
@Prop({ required: true })
name: string;

@Prop({ required: true })
description: string;
}

export const CategorySchema = SchemaFactory.createForClass(Category);
45 changes: 45 additions & 0 deletions backend/src/schemas/event.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Types } from 'mongoose';

@Schema({ timestamps: true })
export class Event {
@Prop({ type: Types.ObjectId, ref: 'User', required: true })
user: Types.ObjectId;

@Prop({ type: Types.ObjectId, ref: 'Category', required: true })
category: Types.ObjectId;

@Prop({ required: true })
title: string;

@Prop({ required: true })
description: string;

@Prop({
type: [
{
type: {
type: String,
enum: ['Basic', 'Premium', 'VIP'],
required: true,
},
price: { type: Number, required: true },
},
],
})
attributes: { type: string; price: number }[];

@Prop({ required: true })
photos: string[];

@Prop({ required: true })
ratingTotal: number;

@Prop({ required: true })
ratingCount: number;

@Prop({ default: false })
isDeleted: boolean;
}

export const EventSchema = SchemaFactory.createForClass(Event);
19 changes: 19 additions & 0 deletions backend/src/schemas/notification.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Types } from 'mongoose';

@Schema({ timestamps: true })
export class Notification {
@Prop({ type: Types.Array<Types.ObjectId>, ref: 'User', required: false })
users: Types.ObjectId[];

@Prop({ type: Types.Array<Types.ObjectId>, ref: 'Event', required: false })
events: Types.ObjectId[];

@Prop({ required: true })
title: string;

@Prop({ required: true })
message: string;
}

export const NotificationSchema = SchemaFactory.createForClass(Notification);
19 changes: 19 additions & 0 deletions backend/src/schemas/payment.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Types } from 'mongoose';

@Schema({ timestamps: true })
export class Payment {
@Prop({ type: Types.ObjectId, ref: 'Voucher', required: true })
voucher: Types.ObjectId;

@Prop({ required: true })
method: 'momo' | 'zalo-pay' | 'vn-pay';

@Prop({ required: true })
originPrice: number;

@Prop({ required: true })
finalPrice: number;
}

export const PaymentSchema = SchemaFactory.createForClass(Payment);
19 changes: 19 additions & 0 deletions backend/src/schemas/review.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Types } from 'mongoose';

@Schema({ timestamps: true })
export class Review {
@Prop({ type: Types.ObjectId, ref: 'Event', required: true })
event: Types.ObjectId;

@Prop({ type: Types.ObjectId, ref: 'User', required: true })
user: Types.ObjectId;

@Prop({ required: true })
rating: number;

@Prop({ required: true })
comment: string;
}

export const ReviewSchema = SchemaFactory.createForClass(Review);
42 changes: 42 additions & 0 deletions backend/src/schemas/user.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';

@Schema({ timestamps: true })
export class User {
@Prop({ required: true })
fullName: string;

@Prop({ required: true })
email: string;

@Prop({ required: true })
hashedPassword: string;

@Prop({ required: true })
phoneNumber: string;

@Prop({ required: true })
address: string;

@Prop({ required: true })
dateOfBirth: Date;

@Prop({ required: true })
gender: 'male' | 'female';

@Prop({ required: true })
avatar: string;

@Prop({ required: true })
role: 'user' | 'admin' | 'super-admin';

@Prop({ required: false })
verificationCode: string;

@Prop({ required: false })
verificationCodeExpires: Date;

@Prop({ default: false })
isVerified: boolean;
}

export const UserSchema = SchemaFactory.createForClass(User);
37 changes: 37 additions & 0 deletions backend/src/schemas/voucher.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Types } from 'mongoose';

@Schema({ timestamps: true })
export class Voucher {
@Prop({ type: Types.ObjectId, ref: 'User', required: true })
user: Types.ObjectId;

@Prop({ required: true, unique: true })
code: string;

@Prop({ required: true })
title: string;

@Prop({ required: true })
description: string;

@Prop({ required: true })
value: number;

@Prop({ required: true })
start: Date;

@Prop({ required: true })
end: Date;

@Prop({ required: true })
maxUses: number;

@Prop({ required: true })
usedCount: number;

@Prop({ default: false })
isDeleted: boolean;
}

export const VoucherSchema = SchemaFactory.createForClass(Voucher);
Empty file removed backend/src/utils/.gitkeep
Empty file.
12 changes: 12 additions & 0 deletions backend/src/utils/hash.util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as argon2 from 'argon2';

export const hash = async (plainPassword: string): Promise<string> => {
return await argon2.hash(plainPassword);
};

export const verify = async (
hashedPassword: string,
plainPassword: string,
): Promise<boolean> => {
return await argon2.verify(hashedPassword, plainPassword);
};
Loading