init commit,

This commit is contained in:
louiscklaw
2025-05-28 09:55:51 +08:00
commit efe70ceb69
8042 changed files with 951668 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
import httpStatus from 'http-status';
import catchAsync from '../utils/catchAsync';
import { authService, userService, tokenService, emailService } from '../services';
import exclude from '../utils/exclude';
import { User } from '@prisma/client';
const register = catchAsync(async (req, res) => {
const { email, password } = req.body;
const user = await userService.createUser(email, password);
const userWithoutPassword = exclude(user, ['password', 'createdAt', 'updatedAt']);
const tokens = await tokenService.generateAuthTokens(user);
res.status(httpStatus.CREATED).send({ user: userWithoutPassword, tokens });
});
const login = catchAsync(async (req, res) => {
const { email, password } = req.body;
const user = await authService.loginUserWithEmailAndPassword(email, password);
const tokens = await tokenService.generateAuthTokens(user);
res.send({ user, tokens });
});
const logout = catchAsync(async (req, res) => {
await authService.logout(req.body.refreshToken);
res.status(httpStatus.NO_CONTENT).send();
});
const refreshTokens = catchAsync(async (req, res) => {
const tokens = await authService.refreshAuth(req.body.refreshToken);
res.send({ ...tokens });
});
const forgotPassword = catchAsync(async (req, res) => {
const resetPasswordToken = await tokenService.generateResetPasswordToken(req.body.email);
await emailService.sendResetPasswordEmail(req.body.email, resetPasswordToken);
res.status(httpStatus.NO_CONTENT).send();
});
const resetPassword = catchAsync(async (req, res) => {
await authService.resetPassword(req.query.token as string, req.body.password);
res.status(httpStatus.NO_CONTENT).send();
});
const sendVerificationEmail = catchAsync(async (req, res) => {
const user = req.user as User;
const verifyEmailToken = await tokenService.generateVerifyEmailToken(user);
await emailService.sendVerificationEmail(user.email, verifyEmailToken);
res.status(httpStatus.NO_CONTENT).send();
});
const verifyEmail = catchAsync(async (req, res) => {
await authService.verifyEmail(req.query.token as string);
res.status(httpStatus.NO_CONTENT).send();
});
export default {
register,
login,
logout,
refreshTokens,
forgotPassword,
resetPassword,
sendVerificationEmail,
verifyEmail
};

View File

@@ -0,0 +1,54 @@
import httpStatus from 'http-status';
import pick from '../utils/pick';
import ApiError from '../utils/ApiError';
import catchAsync from '../utils/catchAsync';
import { userService } from '../services';
import eventService from '../services/event.service';
// const createUser = catchAsync(async (req, res) => {
// const { email, password, name, role } = req.body;
// const user = await userService.createUser(email, password, name, role);
// res.status(httpStatus.CREATED).send(user);
// });
// const getUsers = catchAsync(async (req, res) => {
// const filter = pick(req.query, ['name', 'role']);
// const options = pick(req.query, ['sortBy', 'limit', 'page']);
// const result = await userService.queryUsers(filter, options);
// res.send(result);
// });
const getEvents = catchAsync(async (req, res) => {
const filter = pick(req.query, ['name', 'role']);
const options = pick(req.query, ['sortBy', 'limit', 'page']);
const result = await eventService.queryEvents(filter, options);
res.send(result);
});
const getEvent = catchAsync(async (req, res) => {
const eventId = parseInt(req.params.eventId);
const event = await eventService.getEventById(eventId);
if (!event) {
throw new ApiError(httpStatus.NOT_FOUND, 'Event not found');
}
res.send(event);
});
// const updateUser = catchAsync(async (req, res) => {
// const user = await userService.updateUserById(req.params.userId, req.body);
// res.send(user);
// });
// const deleteUser = catchAsync(async (req, res) => {
// await userService.deleteUserById(req.params.userId);
// res.status(httpStatus.NO_CONTENT).send();
// });
export default {
// createUser,
getEvents,
getEvent
// getUser
// updateUser,
// deleteUser
};

View File

@@ -0,0 +1,9 @@
import catchAsync from '../utils/catchAsync';
const getHelloworld = catchAsync(async (req, res) => {
res.send({ hello: 'world' });
});
export default {
getHelloworld
};

View File

@@ -0,0 +1,2 @@
export { default as authController } from './auth.controller';
export { default as userController } from './user.controller';

View File

@@ -0,0 +1,55 @@
import httpStatus from 'http-status';
import pick from '../utils/pick';
import ApiError from '../utils/ApiError';
import catchAsync from '../utils/catchAsync';
import { userService } from '../services';
import eventService from '../services/event.service';
import memberService from '../services/member.service';
// const createUser = catchAsync(async (req, res) => {
// const { email, password, name, role } = req.body;
// const user = await userService.createUser(email, password, name, role);
// res.status(httpStatus.CREATED).send(user);
// });
// const getUsers = catchAsync(async (req, res) => {
// const filter = pick(req.query, ['name', 'role']);
// const options = pick(req.query, ['sortBy', 'limit', 'page']);
// const result = await userService.queryUsers(filter, options);
// res.send(result);
// });
const getMembers = catchAsync(async (req, res) => {
const filter = pick(req.query, ['name', 'role']);
const options = pick(req.query, ['sortBy', 'limit', 'page']);
const result = await memberService.queryMembers(filter, options);
res.send(result);
});
const getMember = catchAsync(async (req, res) => {
const memberId = parseInt(req.params.memberId);
const member = await memberService.getMemberById(memberId);
if (!member) {
throw new ApiError(httpStatus.NOT_FOUND, 'Member not found');
}
res.send(member);
});
// const updateUser = catchAsync(async (req, res) => {
// const user = await userService.updateUserById(req.params.userId, req.body);
// res.send(user);
// });
// const deleteUser = catchAsync(async (req, res) => {
// await userService.deleteUserById(req.params.userId);
// res.status(httpStatus.NO_CONTENT).send();
// });
export default {
// createUser,
getMembers,
getMember
// getUser
// updateUser,
// deleteUser
};

View File

@@ -0,0 +1,63 @@
// REQ0047/order-page
//
// PURPOSE:
// - provide api access to backend db for orders
//
// RULES:
// - T.B.A.
//
import httpStatus from 'http-status';
import pick from '../utils/pick';
import ApiError from '../utils/ApiError';
import catchAsync from '../utils/catchAsync';
import { userService } from '../services';
import eventService from '../services/event.service';
import orderService from '../services/order.service';
// const createUser = catchAsync(async (req, res) => {
// const { email, password, name, role } = req.body;
// const user = await userService.createUser(email, password, name, role);
// res.status(httpStatus.CREATED).send(user);
// });
// const getUsers = catchAsync(async (req, res) => {
// const filter = pick(req.query, ['name', 'role']);
// const options = pick(req.query, ['sortBy', 'limit', 'page']);
// const result = await userService.queryUsers(filter, options);
// res.send(result);
// });
const getOrders = catchAsync(async (req, res) => {
const filter = pick(req.query, ['name', 'role']);
const options = pick(req.query, ['sortBy', 'limit', 'page']);
const result = await orderService.queryOrders(filter, options);
res.send(result);
});
const getOrder = catchAsync(async (req, res) => {
const eventId = parseInt(req.params.eventId);
const event = await orderService.getOrderById(eventId);
if (!event) {
throw new ApiError(httpStatus.NOT_FOUND, 'Event not found');
}
res.send(event);
});
// const updateUser = catchAsync(async (req, res) => {
// const user = await userService.updateUserById(req.params.userId, req.body);
// res.send(user);
// });
// const deleteUser = catchAsync(async (req, res) => {
// await userService.deleteUserById(req.params.userId);
// res.status(httpStatus.NO_CONTENT).send();
// });
export default {
// createUser,
getOrders,
getOrder
// getUser
// updateUser,
// deleteUser
};

View File

@@ -0,0 +1,56 @@
import httpStatus from 'http-status';
import pick from '../utils/pick';
import ApiError from '../utils/ApiError';
import catchAsync from '../utils/catchAsync';
import { userService } from '../services';
import eventService from '../services/event.service';
import memberService from '../services/member.service';
import profileService from '../services/profile.service';
// const createUser = catchAsync(async (req, res) => {
// const { email, password, name, role } = req.body;
// const user = await userService.createUser(email, password, name, role);
// res.status(httpStatus.CREATED).send(user);
// });
// const getUsers = catchAsync(async (req, res) => {
// const filter = pick(req.query, ['name', 'role']);
// const options = pick(req.query, ['sortBy', 'limit', 'page']);
// const result = await userService.queryUsers(filter, options);
// res.send(result);
// });
const getMembers = catchAsync(async (req, res) => {
const filter = pick(req.query, ['name', 'role']);
const options = pick(req.query, ['sortBy', 'limit', 'page']);
const result = await memberService.queryMembers(filter, options);
res.send(result);
});
const getProfile = catchAsync(async (req, res) => {
const profileId = parseInt(req.params.profileId);
const profile = await profileService.getProfileById(profileId);
if (!profile) {
throw new ApiError(httpStatus.NOT_FOUND, 'Profile not found');
}
res.send(profile);
});
// const updateUser = catchAsync(async (req, res) => {
// const user = await userService.updateUserById(req.params.userId, req.body);
// res.send(user);
// });
// const deleteUser = catchAsync(async (req, res) => {
// await userService.deleteUserById(req.params.userId);
// res.status(httpStatus.NO_CONTENT).send();
// });
export default {
// createUser,
getMembers,
getProfile
// getUser
// updateUser,
// deleteUser
};

View File

@@ -0,0 +1,44 @@
import httpStatus from 'http-status';
import pick from '../utils/pick';
import ApiError from '../utils/ApiError';
import catchAsync from '../utils/catchAsync';
import { userService } from '../services';
const createUser = catchAsync(async (req, res) => {
const { email, password, name, role } = req.body;
const user = await userService.createUser(email, password, name, role);
res.status(httpStatus.CREATED).send(user);
});
const getUsers = catchAsync(async (req, res) => {
const filter = pick(req.query, ['name', 'role']);
const options = pick(req.query, ['sortBy', 'limit', 'page']);
const result = await userService.queryUsers(filter, options);
res.send(result);
});
const getUser = catchAsync(async (req, res) => {
const user = await userService.getUserById(req.params.userId);
if (!user) {
throw new ApiError(httpStatus.NOT_FOUND, 'User not found');
}
res.send(user);
});
const updateUser = catchAsync(async (req, res) => {
const user = await userService.updateUserById(req.params.userId, req.body);
res.send(user);
});
const deleteUser = catchAsync(async (req, res) => {
await userService.deleteUserById(req.params.userId);
res.status(httpStatus.NO_CONTENT).send();
});
export default {
createUser,
getUsers,
getUser,
updateUser,
deleteUser
};