diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 5308758..07d06bb 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -20,8 +20,6 @@ model User { email String @unique phoneNumber String - balance Int - collegeName String registrationId String? @@ -29,9 +27,6 @@ model User { teamsRegistered TeamRegistration[] - to Transaction[] @relation("to") - from Transaction[] @relation("from") - manages EventManager[] organizes EventOrganiser[] @@ -125,9 +120,6 @@ model Event { maxTeamSize Int minTeamSize Int - registrationIncentive Int @default(0) - attendanceIncentive Int @default(0) - prizeDescription String stagesDescription String description String @@ -149,35 +141,6 @@ model Event { module Module @relation(fields: [moduleId], references: [id], onDelete: Cascade) teams Team[] - - transactions Transaction[] -} - -enum TransactionReason { - ATTENDANCE - PURCHASE - REGISTRATION - ONLINE_EVENT -} - -model Transaction { - id String @id @default(auto()) @map("_id") @db.ObjectId - - fromUserId String @db.ObjectId - from User @relation(fields: [fromUserId], references: [id], name: "from", onDelete: Restrict) - - toUserId String @db.ObjectId - to User @relation(fields: [toUserId], references: [id], name: "to", onDelete: Restrict) - - amount Int - - reason TransactionReason - description String? - - eventId String? @db.ObjectId - event Event? @relation(fields: [eventId], references: [id], onDelete: Restrict) - - createdAt DateTime @default(now()) } model Statics { diff --git a/server.ts b/server.ts index 5b82c71..3890389 100644 --- a/server.ts +++ b/server.ts @@ -65,7 +65,6 @@ app.use(`${Constants.Server.ROOT}/module`, Routers.Module); app.use(`${Constants.Server.ROOT}/event`, Routers.Event); app.use(`${Constants.Server.ROOT}/team`, Routers.Team); app.use(`${Constants.Server.ROOT}/user`, Routers.User); -app.use(`${Constants.Server.ROOT}/transaction`, Routers.Transaction); app.use(`${Constants.Server.ROOT}/statics`, Routers.Statics); app.use(`${Constants.Server.ROOT}/spark`, Routers.Spark); diff --git a/src/controllers/auth/signUp.ts b/src/controllers/auth/signUp.ts index 2b3fe47..1fabb25 100644 --- a/src/controllers/auth/signUp.ts +++ b/src/controllers/auth/signUp.ts @@ -102,7 +102,6 @@ const signUp: Interfaces.Controller.Async = async (req, res, next) => { await prisma.user.create({ data: { email: process.env.NODE_ENV === "development" ? email : firebaseEmail!, - balance: 0, collegeName: collegeName, registrationId: registrationId, firebaseId: uid, diff --git a/src/controllers/event/update.ts b/src/controllers/event/update.ts index fcbb048..0f7bfd8 100644 --- a/src/controllers/event/update.ts +++ b/src/controllers/event/update.ts @@ -8,8 +8,6 @@ const updateEvent: Interfaces.Controller.Async = async (req, res, next) => { const { description, posterImage, - attendanceIncentive, - registrationIncentive, thirdPartyURL, lat, lng, @@ -75,13 +73,6 @@ const updateEvent: Interfaces.Controller.Async = async (req, res, next) => { managers = [], }: { organizers: string[]; managers: string[] } = req.body; - if ( - (registrationIncentive && !(typeof registrationIncentive === "number")) || - (attendanceIncentive && !(typeof attendanceIncentive === "number")) - ) { - return next(Errors.Module.invalidInput); - } - if (extraQuestions && !Array.isArray(extraQuestions)) { return next(Errors.Module.invalidInput); } @@ -169,8 +160,6 @@ const updateEvent: Interfaces.Controller.Async = async (req, res, next) => { data: { description, posterImage, - attendanceIncentive, - registrationIncentive, thirdPartyURL, lat, lng, diff --git a/src/controllers/index.ts b/src/controllers/index.ts index e57fdd9..79cb0e6 100644 --- a/src/controllers/index.ts +++ b/src/controllers/index.ts @@ -1,11 +1,10 @@ import * as Home from "./home"; import * as Module from "./module"; import * as Event from "./event"; -import * as Transaction from "./transaction"; import * as Team from "./team"; import * as User from "./user"; import * as Auth from "./auth"; import * as Statics from "./statics"; import * as Spark from "./spark"; -export { Home, Transaction, Team, Module, Event, User, Auth, Statics, Spark }; +export { Home, Team, Module, Event, User, Auth, Statics, Spark }; diff --git a/src/controllers/module/get.ts b/src/controllers/module/get.ts index 82ea683..f51aa16 100644 --- a/src/controllers/module/get.ts +++ b/src/controllers/module/get.ts @@ -18,8 +18,6 @@ const getAllModules: Interfaces.Controller.Async = async (_req, res, next) => { id: true, name: true, posterImage: true, - attendanceIncentive: true, - registrationIncentive: true, description: true, registrationEndTime: true, registrationStartTime: true, diff --git a/src/controllers/team/register.ts b/src/controllers/team/register.ts index bea53a2..bf98030 100644 --- a/src/controllers/team/register.ts +++ b/src/controllers/team/register.ts @@ -1,10 +1,5 @@ import { prisma } from "@utils/prisma"; -import { - Prisma, - RegistrationStatus, - TeamMemberRole, - TransactionReason, -} from "@prisma/client"; +import { Prisma, RegistrationStatus, TeamMemberRole } from "@prisma/client"; import * as Interfaces from "@interfaces"; import * as Success from "@success"; @@ -44,7 +39,6 @@ const registerTeam: Interfaces.Controller.Async = async (req, res, next) => { registrationStartTime: true, registrationEndTime: true, moduleId: true, - registrationIncentive: true, }, }); @@ -157,56 +151,6 @@ const registerTeam: Interfaces.Controller.Async = async (req, res, next) => { }); }); - // Registration incentive if team size is 1. - - if (members.size === 1) { - // Check for admin insufficient balance - - await prisma.transaction.create({ - data: { - amount: event.registrationIncentive, - reason: TransactionReason.REGISTRATION, - event: { - connect: { - id: event.id, - }, - }, - from: { - connect: { - firebaseId: req.admin!.firebaseId, - }, - }, - to: { - connect: { - firebaseId: req.user!.firebaseId, - // User is the leader of the 1-member team - }, - }, - }, - }); - - // User balance update - await prisma.user.update({ - where: { - id: req.user!.id, - }, - data: { - balance: req.user!.balance + event!.registrationIncentive, - }, - }); - - // Admin balance update - await prisma.user.update({ - where: { - firebaseId: req.admin!.firebaseId, - }, - data: { - balance: req.admin!.balance - event!.registrationIncentive * 1, - // 1 member team - }, - }); - } - await prisma.team.create({ data: { teamName: name, diff --git a/src/controllers/team/respond.ts b/src/controllers/team/respond.ts index c39e53b..71acff0 100644 --- a/src/controllers/team/respond.ts +++ b/src/controllers/team/respond.ts @@ -1,11 +1,5 @@ import { prisma } from "@utils/prisma"; -import { - Prisma, - RegistrationStatus, - Transaction, - TransactionReason, - User, -} from "@prisma/client"; +import { RegistrationStatus } from "@prisma/client"; import * as Interfaces from "@interfaces"; import * as Errors from "@errors"; @@ -55,7 +49,6 @@ const teamRegistrationResponse: Interfaces.Controller.Async = async ( user: { select: { firebaseId: true, - balance: true, }, }, }, @@ -84,14 +77,6 @@ const teamRegistrationResponse: Interfaces.Controller.Async = async ( return next(Errors.Team.userAlreadyResponded); } - const event = await prisma.event.findFirst({ - where: { - id: team.eventId, - }, - }); - - // Check for admin insufficient balance - // Cancel Team Registration if (status === RegistrationStatus.CANCELLED) { await prisma.team.update({ @@ -185,60 +170,6 @@ const teamRegistrationResponse: Interfaces.Controller.Async = async ( registrationStatus: RegistrationStatus.REGISTERED, }, }); - - const transactions: Prisma.Prisma__TransactionClient[] = - []; - const userUpdate: Prisma.Prisma__UserClient[] = []; - - team.members.forEach((member) => { - transactions.push( - prisma.transaction.create({ - data: { - amount: event!.registrationIncentive, - reason: TransactionReason.REGISTRATION, - event: { - connect: { - id: event!.id, - }, - }, - from: { - connect: { - firebaseId: req.admin!.firebaseId, - }, - }, - to: { - connect: { - firebaseId: member.user.firebaseId, - }, - }, - }, - }) - ); - userUpdate.push( - prisma.user.update({ - where: { - id: member.userId, - }, - data: { - balance: member.user.balance + event!.registrationIncentive, - }, - }) - ); - }); - - await Promise.all(transactions); - await Promise.all(userUpdate); - - await prisma.user.update({ - where: { - firebaseId: req.admin!.firebaseId, - }, - data: { - balance: - req.admin!.balance - - event!.registrationIncentive * team.members.length, - }, - }); } }); } diff --git a/src/controllers/transaction/get.ts b/src/controllers/transaction/get.ts deleted file mode 100644 index d286bf6..0000000 --- a/src/controllers/transaction/get.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { prisma } from "@utils/prisma"; - -import * as Interfaces from "@interfaces"; -import * as Utils from "@utils"; -import * as Success from "@success"; - -const getAllTransactions: Interfaces.Controller.Async = async (_req, res) => { - const transactions = await prisma.transaction.findMany({}); - - res.json(Success.Transaction.getAllTransactionResponse(transactions)); -}; - -const getAllTransactionsForAUser: Interfaces.Controller.Async = async ( - req, - res -) => { - const transactions = await prisma.transaction.findMany({ - where: { - OR: [ - { - fromUserId: req.user!.id, - }, - { - toUserId: req.user!.id, - }, - ], - }, - }); - - return res.json( - Utils.Response.Success( - Utils.Transaction.transactionsResponse(transactions, req.user!.id) - ) - ); -}; - -export { getAllTransactions, getAllTransactionsForAUser }; diff --git a/src/controllers/transaction/index.ts b/src/controllers/transaction/index.ts deleted file mode 100644 index 31b6096..0000000 --- a/src/controllers/transaction/index.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { getAllTransactions, getAllTransactionsForAUser } from "./get"; -import { - createNewAttendanceTransaction, - createNewPurchaseTransaction, - createNewOnlineEventTransaction, -} from "./new"; - -export { - getAllTransactions, - getAllTransactionsForAUser, - createNewAttendanceTransaction, - createNewPurchaseTransaction, - createNewOnlineEventTransaction, -}; diff --git a/src/controllers/transaction/new.ts b/src/controllers/transaction/new.ts deleted file mode 100644 index fdc0c0e..0000000 --- a/src/controllers/transaction/new.ts +++ /dev/null @@ -1,287 +0,0 @@ -import { prisma } from "@utils/prisma"; - -import * as Constants from "@constants"; -import * as Interfaces from "@interfaces"; -import * as Success from "@success"; -import * as Errors from "@errors"; -import { TransactionReason } from "@prisma/client"; - -const createNewAttendanceTransaction: Interfaces.Controller.Async = async ( - req, - res, - next -) => { - try { - const { toUserName, eventId } = - req.body as Interfaces.Transaction.CreateAttendanceTransactionBody; - - const toUser = await prisma.user.findFirst({ - where: { - username: toUserName, - }, - }); - - const event = await prisma.event.findFirst({ - where: { id: String(eventId) }, - }); - - if (!toUser || !event) { - return next(Errors.Transaction.transactionFailed); - } - - const userTransaction = await prisma.transaction.findFirst({ - where: { - toUserId: toUser.id, - eventId: event.id, - reason: "ATTENDANCE", - }, - }); - - if (userTransaction) { - return next(Errors.Transaction.alreadyAttended); - } - - if (event.attendanceIncentive > 0) { - const amount = event.attendanceIncentive; - - if (req.admin!.balance < amount) { - return next(Errors.Transaction.insufficientBalance); - } - - const transactionCreate = prisma.transaction.create({ - data: { - amount, - reason: TransactionReason.ATTENDANCE, - event: { - connect: { - id: event.id, - }, - }, - from: { - connect: { - firebaseId: req.admin!.firebaseId, - }, - }, - to: { - connect: { - firebaseId: toUser.firebaseId, - }, - }, - }, - }); - - const adminUpdate = prisma.user.update({ - where: { - firebaseId: req.admin!.firebaseId, - }, - data: { - balance: req.admin!.balance - amount, - }, - }); - - const toUserUpdate = prisma.user.update({ - where: { - firebaseId: toUser.firebaseId, - }, - data: { - balance: toUser.balance + amount, - }, - }); - - await prisma.$transaction([transactionCreate, adminUpdate, toUserUpdate]); - } else { - await prisma.transaction.create({ - data: { - amount: 0, - reason: TransactionReason.ATTENDANCE, - event: { - connect: { - id: event.id, - }, - }, - from: { - connect: { - firebaseId: req.admin!.firebaseId, - }, - }, - to: { - connect: { - firebaseId: toUser.firebaseId, - }, - }, - }, - }); - } - - return res.json(Success.Transaction.transactionComplete); - } catch (err) { - console.log(err); - return next(Errors.Transaction.transactionFailed); - } -}; - -const createNewOnlineEventTransaction: Interfaces.Controller.Async = async ( - req, - res, - next -) => { - try { - const { toUserName, amount } = - req.body as Interfaces.Transaction.CreateOnlineEventTransaction; - - const toUser = await prisma.user.findFirst({ - where: { - username: toUserName, - }, - }); - - if (amount < 0) { - return next(Errors.Transaction.transactionInvalidAmount); - } - - if (!toUser) { - return next(Errors.Transaction.transactionFailed); - } - - if (req.admin!.balance < amount) { - return next(Errors.Transaction.insufficientBalance); - } - - const transactionCreate = prisma.transaction.create({ - data: { - amount, - reason: TransactionReason.ONLINE_EVENT, - from: { - connect: { - firebaseId: req.admin!.firebaseId, - }, - }, - to: { - connect: { - firebaseId: toUser.firebaseId, - }, - }, - }, - }); - - const adminUpdate = prisma.user.update({ - where: { - firebaseId: req.admin!.firebaseId, - }, - data: { - balance: req.admin!.balance - amount, - }, - }); - - const toUserUpdate = prisma.user.update({ - where: { - firebaseId: toUser.firebaseId, - }, - data: { - balance: toUser.balance + amount, - }, - }); - - await prisma.$transaction([transactionCreate, adminUpdate, toUserUpdate]); - - return res.json(Success.Transaction.transactionComplete); - } catch (err) { - console.log(err); - return next(Errors.Transaction.transactionFailed); - } -}; - -const createNewPurchaseTransaction: Interfaces.Controller.Async = async ( - req, - res, - next -) => { - try { - const { amount, toUserName } = - req.body as Interfaces.Transaction.CreatePurchaseTransactionBody; - - const admin = await prisma.user.findFirst({ - where: { - username: toUserName, - }, - }); - - if (!admin) { - return next(Errors.Transaction.transactionFailed); - } - - if (req.user!.balance < amount) { - return next(Errors.Transaction.insufficientBalance); - } - - const transaction = await prisma.transaction.findFirst({ - where: { - from: { - firebaseId: req.user!.firebaseId, - }, - }, - orderBy: { createdAt: "desc" }, - }); - - if (transaction) { - if ( - new Date().getTime() - new Date(transaction.createdAt).getTime() < - Constants.Transaction.TRANSACTION_COOLDOWN - ) { - return next(Errors.Transaction.transactionTooQuick); - } - } - - if (amount < 0) { - return next(Errors.Transaction.transactionInvalidAmount); - } - - const transactionCreate = prisma.transaction.create({ - data: { - amount, - reason: TransactionReason.PURCHASE, - from: { - connect: { - firebaseId: req.user!.firebaseId, - }, - }, - to: { - connect: { - firebaseId: admin.firebaseId, - }, - }, - }, - }); - - const userUpdate = prisma.user.update({ - where: { - firebaseId: req.user!.firebaseId, - }, - data: { - balance: req.user!.balance - amount, - }, - }); - - const adminUpdate = prisma.user.update({ - where: { - firebaseId: admin.firebaseId, - }, - data: { - balance: admin.balance + amount, - }, - }); - - await prisma.$transaction([transactionCreate, userUpdate, adminUpdate]); - - return res.json(Success.Transaction.transactionComplete); - } catch (err) { - console.log(err); - return next(Errors.Transaction.transactionFailed); - } -}; - -export { - createNewAttendanceTransaction, - createNewPurchaseTransaction, - createNewOnlineEventTransaction, -}; diff --git a/src/controllers/user/getAllAttendedEvents.ts b/src/controllers/user/getAllAttendedEvents.ts deleted file mode 100644 index a526714..0000000 --- a/src/controllers/user/getAllAttendedEvents.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { prisma } from "@utils/prisma"; - -import * as Interfaces from "@interfaces"; -import * as Utils from "@utils"; -import { TransactionReason } from "@prisma/client"; - -const getAllAttendedEventsOfUser: Interfaces.Controller.Async = async ( - req, - res -) => { - const transactions = await prisma.transaction.findMany({ - where: { - to: { - firebaseId: req.user!.firebaseId, - }, - reason: TransactionReason.ATTENDANCE, - }, - select: { - id: true, - amount: true, - description: true, - reason: true, - createdAt: true, - event: { - select: { - id: true, - name: true, - }, - }, - }, - }); - - return res.json(Utils.Response.Success(transactions)); -}; - -export { getAllAttendedEventsOfUser }; diff --git a/src/controllers/user/getOne.ts b/src/controllers/user/getOne.ts index e6e1005..09bc59e 100644 --- a/src/controllers/user/getOne.ts +++ b/src/controllers/user/getOne.ts @@ -19,8 +19,6 @@ const getOneUserById: Interfaces.Controller.Async = async (req, res, next) => { include: { manages: true, organizes: true, - to: true, - from: true, teamsRegistered: true, }, }); diff --git a/src/controllers/user/index.ts b/src/controllers/user/index.ts index 7ded296..ee84832 100644 --- a/src/controllers/user/index.ts +++ b/src/controllers/user/index.ts @@ -1,14 +1,12 @@ import { getAllUsers, searchUsers } from "./get"; import { getOneUserById } from "./getOne"; import { getLogedInUser } from "./getLogedInUser"; -import { getAllAttendedEventsOfUser } from "./getAllAttendedEvents"; import { updateUserDetails } from "./update"; import { getMyTeams } from "./getMyTeams"; export { getAllUsers, getOneUserById, - getAllAttendedEventsOfUser, updateUserDetails, getLogedInUser, getMyTeams, diff --git a/src/global/errors/index.ts b/src/global/errors/index.ts index 8b26590..2881a58 100644 --- a/src/global/errors/index.ts +++ b/src/global/errors/index.ts @@ -1,6 +1,5 @@ import * as System from "./system"; import * as Module from "./module"; -import * as Transaction from "./transaction"; import * as User from "./user"; import * as Team from "./team"; import * as Auth from "./auth"; @@ -8,4 +7,4 @@ import * as Event from "./event"; import * as Statics from "./statics"; import * as Spark from "./spark"; -export { System, Transaction, User, Statics, Team, Module, Auth, Event, Spark }; +export { System, User, Statics, Team, Module, Auth, Event, Spark }; diff --git a/src/global/errors/transaction.ts b/src/global/errors/transaction.ts deleted file mode 100644 index 7dbce1d..0000000 --- a/src/global/errors/transaction.ts +++ /dev/null @@ -1,29 +0,0 @@ -import * as Utils from "@utils"; - -const transactionUnauthenticated = Utils.Response.Error( - "Transaction is unauthenticated.", - 401 -); -const transactionFailed = Utils.Response.Error("Transaction failed.", 403); -const insufficientBalance = Utils.Response.Error( - "Insufficient balance remaining.", - 424 -); -const transactionInvalidAmount = Utils.Response.Error( - "Invalid amount transaction.", - 400 -); -const transactionTooQuick = Utils.Response.Error( - "You have attempted your transaction too quick.", - 429 -); -const alreadyAttended = Utils.Response.Error("Already attended the event."); - -export { - alreadyAttended, - insufficientBalance, - transactionUnauthenticated, - transactionFailed, - transactionInvalidAmount, - transactionTooQuick, -}; diff --git a/src/global/interfaces/index.ts b/src/global/interfaces/index.ts index cf8d8d1..6f99ecb 100644 --- a/src/global/interfaces/index.ts +++ b/src/global/interfaces/index.ts @@ -1,10 +1,9 @@ import * as JSON from "./json"; import * as Controller from "./controllers"; import * as Middleware from "./middlewares"; -import * as Transaction from "./transaction"; import * as Team from "./team"; import * as Mail from "./mail"; import * as User from "./user"; import * as Statics from "./statics"; -export { JSON, Controller, Middleware, Statics, Transaction, Team, Mail, User }; +export { JSON, Controller, Middleware, Statics, Team, Mail, User }; diff --git a/src/global/interfaces/transaction.ts b/src/global/interfaces/transaction.ts deleted file mode 100644 index d6575bb..0000000 --- a/src/global/interfaces/transaction.ts +++ /dev/null @@ -1,25 +0,0 @@ -interface CreateAttendanceTransactionBody { - toUserName: string; - eventId: string; -} - -interface CreatePurchaseTransactionBody { - toUserName: string; - amount: number; -} - -interface CreateOnlineEventTransaction { - toUserName: string; - amount: number; -} - -interface TransactionBody { - eventId: string; -} - -export { - CreatePurchaseTransactionBody, - CreateAttendanceTransactionBody, - CreateOnlineEventTransaction, - TransactionBody, -}; diff --git a/src/global/success/index.ts b/src/global/success/index.ts index 8381602..5a77739 100644 --- a/src/global/success/index.ts +++ b/src/global/success/index.ts @@ -1,8 +1,7 @@ import * as Home from "./home"; -import * as Transaction from "./transaction"; import * as Team from "./team"; import * as User from "./user"; import * as Statics from "./statics"; import * as Spark from "./spark"; -export { Home, Transaction, Team, User, Statics, Spark }; +export { Home, Team, User, Statics, Spark }; diff --git a/src/global/success/transaction.ts b/src/global/success/transaction.ts deleted file mode 100644 index 10664aa..0000000 --- a/src/global/success/transaction.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { Transaction } from "@prisma/client"; -import * as Utils from "@utils"; - -const getAllTransactionResponse = (transactions: Transaction[]) => - Utils.Response.Success(transactions); - -const transactionComplete = Utils.Response.Success( - "Transaction completed successfully." -); - -export { getAllTransactionResponse, transactionComplete }; diff --git a/src/middlewares/auth.ts b/src/middlewares/auth.ts index df86605..ad42e61 100644 --- a/src/middlewares/auth.ts +++ b/src/middlewares/auth.ts @@ -70,8 +70,6 @@ const validateUser: Interfaces.Middleware.Async = async (req, _res, next) => { select: { name: true, id: true, - attendanceIncentive: true, - registrationIncentive: true, description: true, maxTeamSize: true, minTeamSize: true, @@ -88,8 +86,6 @@ const validateUser: Interfaces.Middleware.Async = async (req, _res, next) => { select: { name: true, id: true, - attendanceIncentive: true, - registrationIncentive: true, description: true, maxTeamSize: true, minTeamSize: true, diff --git a/src/middlewares/index.ts b/src/middlewares/index.ts index 07d0fb4..b93033d 100644 --- a/src/middlewares/index.ts +++ b/src/middlewares/index.ts @@ -1,8 +1,7 @@ -import * as Transaction from "./transaction"; import * as Module from "./module"; import * as Auth from "./auth"; import * as Event from "./event"; import * as Team from "./team"; import * as Upload from "./upload"; -export { Transaction, Module, Auth, Event, Team, Upload }; +export { Module, Auth, Event, Team, Upload }; diff --git a/src/middlewares/transaction.ts b/src/middlewares/transaction.ts deleted file mode 100644 index d0a4afc..0000000 --- a/src/middlewares/transaction.ts +++ /dev/null @@ -1,64 +0,0 @@ -import * as Interfaces from "@interfaces"; - -import * as Errors from "@errors"; -import { prisma } from "@utils/prisma"; - -const isUserEventManager: Interfaces.Middleware.Async = async ( - req, - _res, - next -) => { - if (!req.user) { - return next(Errors.Transaction.transactionUnauthenticated); - } - const { eventId } = req.body as Interfaces.Transaction.TransactionBody; - - if (!String(eventId)) { - return next(Errors.Event.eventDoesntExist); - } - - const isManager = await prisma.event.count({ - where: { - id: String(eventId), - managers: { - some: { - id: req.user!.id, - }, - }, - }, - }); - - if (!isManager) { - return next(Errors.Transaction.transactionUnauthenticated); - } - - return next(); -}; - -const isReceiverAdmin: Interfaces.Middleware.Async = async ( - req, - _res, - next -) => { - const { toUserName } = - req.body as Interfaces.Transaction.CreatePurchaseTransactionBody; - - const admin = await prisma.user.findFirst({ - where: { - username: toUserName, - }, - }); - - if ( - toUserName && - toUserName.length && - admin && - admin.firebaseId === process.env.ADMIN_ID! - ) { - return next(); - } else { - return next(Errors.Auth.adminAuthError); - } -}; - -export { isUserEventManager, isReceiverAdmin }; diff --git a/src/routes/index.ts b/src/routes/index.ts index ab8509f..391f521 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -1,11 +1,10 @@ import Home from "./home"; import Module from "./module"; import Event from "./event"; -import Transaction from "./transaction"; import User from "./user"; import Auth from "./auth"; import Team from "./team"; import Statics from "./statics"; import Spark from "./spark"; -export { Home, Module, Event, Transaction, User, Auth, Team, Statics, Spark }; +export { Home, Module, Event, User, Auth, Team, Statics, Spark }; diff --git a/src/routes/transaction.ts b/src/routes/transaction.ts deleted file mode 100644 index ac041cb..0000000 --- a/src/routes/transaction.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { Router } from "express"; - -import * as Middlewares from "@middlewares"; -import * as Controllers from "@controllers"; - -const router: Router = Router({ mergeParams: true }); - -// ROOT = /api/transaction - -router.post( - "/attendance", - Middlewares.Auth.validateUser, - Middlewares.Transaction.isUserEventManager, - Middlewares.Auth.getAdmin, - Controllers.Transaction.createNewAttendanceTransaction -); - -router.post( - "/purchase", - Middlewares.Auth.validateUser, - Middlewares.Transaction.isReceiverAdmin, - Controllers.Transaction.createNewPurchaseTransaction -); - -router.post( - "/online-event", - Middlewares.Auth.isAdmin, - Middlewares.Auth.getAdmin, - Controllers.Transaction.createNewOnlineEventTransaction -); - -router.get( - "/all", - Middlewares.Auth.isAdmin, - Controllers.Transaction.getAllTransactions -); - -router.get( - "/", - Middlewares.Auth.validateUser, - Controllers.Transaction.getAllTransactionsForAUser -); - -export default router; diff --git a/src/routes/user.ts b/src/routes/user.ts index 27bcb0e..f404e34 100644 --- a/src/routes/user.ts +++ b/src/routes/user.ts @@ -13,11 +13,6 @@ router.get( Middlewares.Auth.validateUser, Controllers.User.getMyTeams ); -router.get( - "/me/attended_events", - Middlewares.Auth.validateUser, - Controllers.User.getAllAttendedEventsOfUser -); router.get( "/me", Middlewares.Auth.validateUser, diff --git a/src/utils/index.ts b/src/utils/index.ts index d626ac0..a1b4283 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -4,18 +4,7 @@ import * as Email from "./email"; import * as Firebase from "./firebase"; import * as Event from "./event"; import * as User from "./user"; -import * as Transaction from "./transaction"; import * as Upload from "./upload"; import * as HTML from "./html"; -export { - Response, - Error, - Email, - Firebase, - Event, - User, - Transaction, - Upload, - HTML, -}; +export { Response, Error, Email, Firebase, Event, User, Upload, HTML }; diff --git a/src/utils/transaction.ts b/src/utils/transaction.ts deleted file mode 100644 index 5a8c17a..0000000 --- a/src/utils/transaction.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { Transaction } from "@prisma/client"; - -const transactionsResponse = (transactions: Transaction[], userId: string) => { - return transactions.map((transaction) => ({ - ...transaction, - amount: transaction.amount, - createdAt: transaction.createdAt, - description: transaction.description, - reason: transaction.reason, - id: transaction.id, - eventId: transaction.eventId, - type: transaction.fromUserId === userId ? "DEBIT" : "CREDIT", - })); -}; - -export { transactionsResponse };