Skip to content

Commit

Permalink
style: fix prettier formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
yousefyasser committed Oct 4, 2024
1 parent 8197618 commit 32f210d
Show file tree
Hide file tree
Showing 10 changed files with 256 additions and 272 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 @@ -65,4 +65,4 @@ const deleteTag = async (req: Request, res: Response) => {
}
};

export { findTagById, createTag, updateTag, deleteTag };
export { findTagById, createTag, updateTag, deleteTag };
95 changes: 47 additions & 48 deletions backend/src/controllers/users/admin.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,50 @@ import { ResponseStatusCodes } from '../../types/ResponseStatusCodes.types';
import { accountType } from '../../types/User.types';

const createAdmin = async (req: Request, res: Response) => {
try {
const admin = req.body;
const newAdmin = await userRepo.createUser(admin);
const response = {
message: 'admin created successfully',
data: { adminId: newAdmin._id },
};

res.status(ResponseStatusCodes.CREATED).json(response);
} catch (error: any) {
logger.error(`Error creating admin: ${error.message}`);
res.status(ResponseStatusCodes.BAD_REQUEST).json({ message: error.message, data: [] });
}
};

const getAdmins = async (req: Request, res: Response) => {
try {
const admins = await userRepo.getUsersByType(accountType.Admin);
const response = {
message: 'admins fetched successfully',
data: { admins: admins },
};

res.status(ResponseStatusCodes.OK).json(response);
} catch (error: any) {
logger.error(`Error fetching admins: ${error.message}`);
res.status(ResponseStatusCodes.BAD_REQUEST).json({ message: error.message, data: [] });
}
};

const updateAdmin = async (req: Request, res: Response) => {
try {
const admin = req.body;
await userRepo.updateUser(req.params.id, admin);
const response = {
message: 'admin updated successfully',
data: { adminId: req.params.id },
};

res.status(ResponseStatusCodes.OK).json(response);
} catch (error: any) {
logger.error(`Error updating admin: ${error.message}`);
res.status(ResponseStatusCodes.BAD_REQUEST).json({ message: error.message, data: [] });
}
};

export { createAdmin, getAdmins, updateAdmin };

try {
const admin = req.body;
const newAdmin = await userRepo.createUser(admin);
const response = {
message: 'admin created successfully',
data: { adminId: newAdmin._id },
};

res.status(ResponseStatusCodes.CREATED).json(response);
} catch (error: any) {
logger.error(`Error creating admin: ${error.message}`);
res.status(ResponseStatusCodes.BAD_REQUEST).json({ message: error.message, data: [] });
}
};

const getAdmins = async (req: Request, res: Response) => {
try {
const admins = await userRepo.getUsersByType(accountType.Admin);
const response = {
message: 'admins fetched successfully',
data: { admins: admins },
};

res.status(ResponseStatusCodes.OK).json(response);
} catch (error: any) {
logger.error(`Error fetching admins: ${error.message}`);
res.status(ResponseStatusCodes.BAD_REQUEST).json({ message: error.message, data: [] });
}
};

const updateAdmin = async (req: Request, res: Response) => {
try {
const admin = req.body;
await userRepo.updateUser(req.params.id, admin);
const response = {
message: 'admin updated successfully',
data: { adminId: req.params.id },
};

res.status(ResponseStatusCodes.OK).json(response);
} catch (error: any) {
logger.error(`Error updating admin: ${error.message}`);
res.status(ResponseStatusCodes.BAD_REQUEST).json({ message: error.message, data: [] });
}
};

export { createAdmin, getAdmins, updateAdmin };
82 changes: 41 additions & 41 deletions backend/src/database/models/museum.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,48 @@ import { Schema, model } from 'mongoose';
import { locationSchema } from './location.model';

const museumSchema = new Schema({
name: {
type: String,
required: true,
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,
required: true,
min: 0,
},
tags: {
type: [{ type: Schema.Types.ObjectId, ref: 'tag' }],
},
description: {
type: String,
required: true,
native: {
type: Number,
required: true,
min: 0,
},
category:{
type: String,
required: true,
student: {
type: Number,
required: true,
min: 0,
},
pictures: {
type: [String],
},
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,
}
}
});
},
});

export const Museum = model('museum', museumSchema);
export const Museum = model('museum', museumSchema);
44 changes: 22 additions & 22 deletions backend/src/database/repositories/tag.repo.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { ObjectId } from "mongodb";
import { Tag } from "../models/tag.model";
import { TagType } from "../../types/Tag.types";
import Validator from "../../utils/Validator.utils";
import { ObjectId } from 'mongodb';
import { Tag } from '../models/tag.model';
import { TagType } from '../../types/Tag.types';
import Validator from '../../utils/Validator.utils';

class TagRepo{
async findTagById(id: string){
Validator.validateId(id, 'Invalid tag ID');
return await Tag.find({ _id: new ObjectId(id) });
}
class TagRepo {
async findTagById(id: string) {
Validator.validateId(id, 'Invalid tag ID');
return await Tag.find({ _id: new ObjectId(id) });
}

async createTag(tag: TagType){
const tagRes = await Tag.create(tag);
return tagRes;
}
async createTag(tag: TagType) {
const tagRes = await Tag.create(tag);
return tagRes;
}

async updateTag(id: string, tag: TagType){
Validator.validateId(id, 'Invalid tag ID');
return await Tag.updateOne({ _id: new ObjectId(id) }, tag);
}
async updateTag(id: string, tag: TagType) {
Validator.validateId(id, 'Invalid tag ID');
return await Tag.updateOne({ _id: new ObjectId(id) }, tag);
}

async deleteTag(id: string){
Validator.validateId(id, 'Invalid tag ID');
return await Tag.deleteOne({ _id: new ObjectId(id) });
}
async deleteTag(id: string) {
Validator.validateId(id, 'Invalid tag ID');
return await Tag.deleteOne({ _id: new ObjectId(id) });
}
}
export default new TagRepo();
export default new TagRepo();
7 changes: 3 additions & 4 deletions backend/src/routes/admin.route.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Router } from "express";
import { createAdmin, updateAdmin, getAdmins } from "../controllers/users/admin.controller";
import { Router } from 'express';
import { createAdmin, updateAdmin, getAdmins } from '../controllers/users/admin.controller';

const router = Router();

router.get('', getAdmins);
router.post('', createAdmin);
router.put('/:id', updateAdmin);


export default router;
export default router;
9 changes: 2 additions & 7 deletions backend/src/routes/tag.route.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { Router } from 'express';
import {
findTagById,
createTag,
updateTag,
deleteTag,
} from '../controllers/tag.controller';
import { findTagById, createTag, updateTag, deleteTag } from '../controllers/tag.controller';

const tagRouter = Router();

Expand All @@ -13,4 +8,4 @@ tagRouter.post('/', createTag);
tagRouter.put('/:id', updateTag);
tagRouter.delete('/:id', deleteTag);

export default tagRouter;
export default tagRouter;
8 changes: 4 additions & 4 deletions backend/src/types/Location.types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface LocationType {
name: string;
latitude: number;
longitude: number;
}
name: string;
latitude: number;
longitude: number;
}
31 changes: 15 additions & 16 deletions backend/src/types/Museum.types.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { LocationType } from "./Location.types";
import { TagType } from "./Tag.types";
import { LocationType } from './Location.types';
import { TagType } from './Tag.types';
export interface MuseumType {
id: number;
name: string;
tags: TagType[];
description: string;
category: string;
pictures: string[];
location: LocationType;
opening_hours: string;
ticket_prices: {
foreigner: number;
native: number;
student: number;
id: number;
name: string;
tags: TagType[];
description: string;
category: string;
pictures: string[];
location: LocationType;
opening_hours: string;
ticket_prices: {
foreigner: number;
native: number;
student: number;
};
}

}
Loading

0 comments on commit 32f210d

Please sign in to comment.