Skip to content

Commit

Permalink
Merge pull request #24 from Advanced-computer-lab-2024/backend/sherle…
Browse files Browse the repository at this point in the history
…mious/dev

feat: minor fixes and updates to models/references
  • Loading branch information
Sherlemious authored Oct 5, 2024
2 parents e4f2fc8 + 5e89ec3 commit bf65e0c
Show file tree
Hide file tree
Showing 17 changed files with 355 additions and 291 deletions.
2 changes: 1 addition & 1 deletion backend/src/controllers/tag.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const getAllTags = async (req: Request, res: Response) => {
logger.error(`Error fetching tags: ${error.message}`);
res.status(ResponseStatusCodes.BAD_REQUEST).json({ message: error.message, data: [] });
}
}
};

const findTagById = async (req: Request, res: Response) => {
try {
Expand Down
77 changes: 45 additions & 32 deletions backend/src/database/models/activity.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,52 @@ import { ActivityType } from '../../types/Activity.types';
import { ValidationException } from '../../exceptions/ValidationException';
import { getTagIds } from './tag.model';

const activitySchema = new Schema({
date: {
type: Date,
required: true,
const activitySchema = new Schema(
{
date: {
type: Date,
required: true,
},
time: {
type: String,
required: true,
},
location: {
type: locationSchema,
required: true,
},
price: {
type: Number,
required: true,
min: 0,
},
category: {
type: String,
required: true,
},
tags: {
type: [{ type: Schema.Types.ObjectId, ref: 'tag' }],
},
specialDiscounts: {
type: String,
},
bookingOpen: {
type: Boolean,
required: true,
},
created_by: {
type: Schema.Types.ObjectId,
ref: 'user',
},
modified_by: {
type: Schema.Types.ObjectId,
ref: 'user',
},
},
time: {
type: String,
required: true,
},
location: {
type: locationSchema,
required: true,
},
price: {
type: Number,
required: true,
min: 0,
},
category: {
type: String,
required: true,
},
tags: {
type: [{ type: Schema.Types.ObjectId, ref: 'tag' }],
},
specialDiscounts: {
type: String,
},
bookingOpen: {
type: Boolean,
required: true,
},
});
{
timestamps: true,
}
);

async function getActivityIds(activitiesData: ActivityType[]): Promise<ActivityType[]> {
const activityIds: ActivityType[] = [];
Expand Down
31 changes: 18 additions & 13 deletions backend/src/database/models/attachment.model.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import { Schema, model } from 'mongoose';

const attachmentSchema = new Schema({
original_name: {
type: String,
required: true,
const attachmentSchema = new Schema(
{
original_name: {
type: String,
required: true,
},
url: {
type: String,
required: true,
},
created_by: {
type: Schema.Types.ObjectId,
ref: 'user',
},
},
url: {
type: String,
required: true,
},
timestamp: {
type: Date,
default: Date.now,
},
});
{
timestamps: true,
}
);

const Attachment = model('attachment', attachmentSchema);

Expand Down
105 changes: 59 additions & 46 deletions backend/src/database/models/itinerary.model.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,66 @@
import { Schema, model } from 'mongoose';
import { locationSchema } from './location.model';

const itinerarySchema = new Schema({
name: {
type: String,
required: true,
const itinerarySchema = new Schema(
{
name: {
type: String,
required: true,
},
category: {
type: String,
required: true,
},
tags: {
type: [{ type: Schema.Types.ObjectId, ref: 'tag' }],
},
activities: {
type: [{ activity: { type: Schema.Types.ObjectId, ref: 'activity' }, duration: Number }],
},
locations: {
type: [locationSchema],
},
timeline: {
type: String,
},
language: {
type: String,
required: true,
},
price: {
type: Number,
required: true,
min: 0,
},
available_datetimes: {
type: [Date],
required: true,
},
accessibility: {
type: Boolean,
required: true,
},
pick_up_location: {
type: locationSchema,
required: true,
},
drop_off_location: {
type: locationSchema,
required: true,
},
created_by: {
type: Schema.Types.ObjectId,
ref: 'user',
},
modified_by: {
type: Schema.Types.ObjectId,
ref: 'user',
},
},
category: {
type: String,
required: true,
},
tags: {
type: [{ type: Schema.Types.ObjectId, ref: 'tag' }],
},
activities: {
type: [{ type: Schema.Types.ObjectId, ref: 'activity' }],
},
locations: {
type: [locationSchema],
},
timeline: {
type: String,
},
language: {
type: String,
required: true,
},
price: {
type: Number,
required: true,
min: 0,
},
available_datetimes: {
type: [Date],
required: true,
},
accessibility: {
type: Boolean,
required: true,
},
pick_up_location: {
type: locationSchema,
required: true,
},
drop_off_location: {
type: locationSchema,
required: true,
},
});
{
timestamps: true,
}
);

const Itinerary = model('itinerary', itinerarySchema);

Expand Down
87 changes: 50 additions & 37 deletions backend/src/database/models/museum.model.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,62 @@
import { Schema, model } from 'mongoose';
import { locationSchema } from './location.model';

const museumSchema = new Schema({
name: {
type: String,
required: true,
},
tags: {
type: [{ type: Schema.Types.ObjectId, ref: 'tag' }],
},
description: {
type: String,
required: true,
},
category: {
type: String,
required: true,
},
pictures: {
type: [String],
},
location: {
type: locationSchema,
},
opening_hours: {
type: String,
required: true,
},
ticket_prices: {
foreigner: {
type: Number,
const museumSchema = new Schema(
{
name: {
type: String,
required: true,
min: 0,
},
native: {
type: Number,
tags: {
type: [{ type: Schema.Types.ObjectId, ref: 'tag' }],
},
description: {
type: String,
required: true,
min: 0,
},
student: {
type: Number,
category: {
type: String,
required: true,
min: 0,
},
pictures: {
type: [{ type: Schema.Types.ObjectId, ref: 'attachment' }],
},
location: {
type: locationSchema,
},
opening_hours: {
type: String,
required: true,
},
ticket_prices: {
foreigner: {
type: Number,
required: true,
min: 0,
},
native: {
type: Number,
required: true,
min: 0,
},
student: {
type: Number,
required: true,
min: 0,
},
},
created_by: {
type: Schema.Types.ObjectId,
ref: 'user',
},
modified_by: {
type: Schema.Types.ObjectId,
ref: 'user',
},
},
});
{
timestamps: true,
}
);

export const Museum = model('museum', museumSchema);
Loading

0 comments on commit bf65e0c

Please sign in to comment.