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

rm tecnocoin transactions #32

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,13 @@ model User {
email String @unique
phoneNumber String

balance Int

collegeName String
registrationId String?

imageUrl String

teamsRegistered TeamRegistration[]

to Transaction[] @relation("to")
from Transaction[] @relation("from")

manages EventManager[]

organizes EventOrganiser[]
Expand Down Expand Up @@ -125,9 +120,6 @@ model Event {
maxTeamSize Int
minTeamSize Int

registrationIncentive Int @default(0)
attendanceIncentive Int @default(0)

prizeDescription String
stagesDescription String
description String
Expand All @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 0 additions & 1 deletion src/controllers/auth/signUp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 0 additions & 11 deletions src/controllers/event/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ const updateEvent: Interfaces.Controller.Async = async (req, res, next) => {
const {
description,
posterImage,
attendanceIncentive,
registrationIncentive,
thirdPartyURL,
lat,
lng,
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -169,8 +160,6 @@ const updateEvent: Interfaces.Controller.Async = async (req, res, next) => {
data: {
description,
posterImage,
attendanceIncentive,
registrationIncentive,
thirdPartyURL,
lat,
lng,
Expand Down
3 changes: 1 addition & 2 deletions src/controllers/index.ts
Original file line number Diff line number Diff line change
@@ -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 };
2 changes: 0 additions & 2 deletions src/controllers/module/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
58 changes: 1 addition & 57 deletions src/controllers/team/register.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -44,7 +39,6 @@ const registerTeam: Interfaces.Controller.Async = async (req, res, next) => {
registrationStartTime: true,
registrationEndTime: true,
moduleId: true,
registrationIncentive: true,
},
});

Expand Down Expand Up @@ -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,
Expand Down
71 changes: 1 addition & 70 deletions src/controllers/team/respond.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -55,7 +49,6 @@ const teamRegistrationResponse: Interfaces.Controller.Async = async (
user: {
select: {
firebaseId: true,
balance: true,
},
},
},
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -185,60 +170,6 @@ const teamRegistrationResponse: Interfaces.Controller.Async = async (
registrationStatus: RegistrationStatus.REGISTERED,
},
});

const transactions: Prisma.Prisma__TransactionClient<Transaction>[] =
[];
const userUpdate: Prisma.Prisma__UserClient<User>[] = [];

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,
},
});
}
});
}
Expand Down
37 changes: 0 additions & 37 deletions src/controllers/transaction/get.ts

This file was deleted.

14 changes: 0 additions & 14 deletions src/controllers/transaction/index.ts

This file was deleted.

Loading
Loading