Skip to content

Commit ef3e168

Browse files
committed
called prettier
1 parent 6b84b93 commit ef3e168

File tree

12 files changed

+135
-138
lines changed

12 files changed

+135
-138
lines changed

backend/typescript/models/entity.model.ts

-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,3 @@ export default class Entity extends Model {
2222
@Column
2323
file_name!: string;
2424
}
25-
+33-32
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// import { Prisma } from "@prisma/client";
22
import { Router } from "express";
3-
import prisma from '../prisma';
3+
import prisma from "../prisma";
44
import DonationService from "../services/implementations/donationService";
55
import IDonationService from "../services/interfaces/donationService";
66
import { getErrorMessage } from "../utilities/errorUtils";
@@ -11,44 +11,45 @@ const donationRouter = Router();
1111

1212
// display all donations
1313
donationRouter.get("/", async (req: any, res: any) => {
14-
try {
15-
const allDonations = await donationService.getAllDonations();
16-
console.log('getting donations');
17-
res.status(200).json(allDonations);
18-
} catch (error) {
19-
res.status(500).json({ error: getErrorMessage(error) });
20-
}
14+
try {
15+
const allDonations = await donationService.getAllDonations();
16+
console.log("getting donations");
17+
res.status(200).json(allDonations);
18+
} catch (error) {
19+
res.status(500).json({ error: getErrorMessage(error) });
20+
}
2121
});
2222

2323
// display all donations made by a user
2424
donationRouter.get("/:id", async (req: any, res: any) => {
25-
const id = req.params.id;
25+
const { id } = req.params;
2626

27-
try {
28-
const userDonations = await donationService.getUserDonation(id);
27+
try {
28+
const userDonations = await donationService.getUserDonation(id);
2929

30-
res.status(200).json(userDonations);
31-
} catch (error) {
32-
res.status(500).json({ error: getErrorMessage(error) });
33-
}
30+
res.status(200).json(userDonations);
31+
} catch (error) {
32+
res.status(500).json({ error: getErrorMessage(error) });
33+
}
3434
});
3535

3636
// Each donation has 1 cause associated with it, the donation from user will be split before calling this route.
3737
donationRouter.post("/give", async (req: any, res: any) => {
38-
try {
39-
const { user_id, amount, cause_id, is_recurring, confirmation_email_sent } = req.body;
40-
41-
const newDonation = await donationService.createDonation(
42-
user_id,
43-
amount,
44-
cause_id,
45-
is_recurring,
46-
confirmation_email_sent
47-
);
48-
res.status(200).json(newDonation);
49-
} catch (error) {
50-
res.status(500).json({ error: getErrorMessage(error) });
51-
}
52-
})
53-
54-
export default donationRouter;
38+
try {
39+
const { user_id, amount, cause_id, is_recurring, confirmation_email_sent } =
40+
req.body;
41+
42+
const newDonation = await donationService.createDonation(
43+
user_id,
44+
amount,
45+
cause_id,
46+
is_recurring,
47+
confirmation_email_sent,
48+
);
49+
res.status(200).json(newDonation);
50+
} catch (error) {
51+
res.status(500).json({ error: getErrorMessage(error) });
52+
}
53+
});
54+
55+
export default donationRouter;

backend/typescript/rest/userRoutes.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ userRouter.post("/", createUserDtoValidator, async (req, res) => {
9595
});
9696

9797
await authService.sendEmailVerificationLink(req.body.email);
98-
98+
9999
res.status(201).json(newUser);
100100
} catch (error: unknown) {
101101
res.status(500).json({ error: getErrorMessage(error) });

backend/typescript/server.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ app.use("/entities", entityRouter);
3737
app.use("/simple-entities", simpleEntityRouter);
3838
app.use("/users", userRouter);
3939
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
40-
app.use('/donations', donationRouter);
40+
app.use("/donations", donationRouter);
4141

4242
// Health check
4343
app.get("/test", async (req: any, res: any) => {
44-
res.status(200).json('endpoint hath been hit');
44+
res.status(200).json("endpoint hath been hit");
4545
});
4646

4747
sequelize.authenticate();

backend/typescript/services/implementations/__tests__/userService.test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ jest.mock("firebase-admin", () => {
2929
return { auth };
3030
});
3131

32-
3332
describe("pg userService", () => {
3433
let userService: UserService;
3534

backend/typescript/services/implementations/authService.ts

+6-9
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,8 @@ class AuthService implements IAuthService {
168168
roles: Set<Role>,
169169
): Promise<boolean> {
170170
try {
171-
const decodedIdToken: firebaseAdmin.auth.DecodedIdToken = await firebaseAdmin
172-
.auth()
173-
.verifyIdToken(accessToken, true);
171+
const decodedIdToken: firebaseAdmin.auth.DecodedIdToken =
172+
await firebaseAdmin.auth().verifyIdToken(accessToken, true);
174173
const userRole = await this.userService.getUserRoleByAuthId(
175174
decodedIdToken.uid,
176175
);
@@ -190,9 +189,8 @@ class AuthService implements IAuthService {
190189
requestedUserId: string,
191190
): Promise<boolean> {
192191
try {
193-
const decodedIdToken: firebaseAdmin.auth.DecodedIdToken = await firebaseAdmin
194-
.auth()
195-
.verifyIdToken(accessToken, true);
192+
const decodedIdToken: firebaseAdmin.auth.DecodedIdToken =
193+
await firebaseAdmin.auth().verifyIdToken(accessToken, true);
196194
const tokenUserId = await this.userService.getUserIdByAuthId(
197195
decodedIdToken.uid,
198196
);
@@ -214,9 +212,8 @@ class AuthService implements IAuthService {
214212
requestedEmail: string,
215213
): Promise<boolean> {
216214
try {
217-
const decodedIdToken: firebaseAdmin.auth.DecodedIdToken = await firebaseAdmin
218-
.auth()
219-
.verifyIdToken(accessToken, true);
215+
const decodedIdToken: firebaseAdmin.auth.DecodedIdToken =
216+
await firebaseAdmin.auth().verifyIdToken(accessToken, true);
220217

221218
const firebaseUser = await firebaseAdmin
222219
.auth()
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,67 @@
11
import IDonationService from "../interfaces/donationService";
2-
import { DonationDTO, Recurrence } from "../../types"
2+
import { DonationDTO, Recurrence } from "../../types";
33
import prisma from "../../prisma";
44
import logger from "../../utilities/logger";
55
import { getErrorMessage } from "../../utilities/errorUtils";
66

77
const Logger = logger(__filename);
88

99
class DonationService implements IDonationService {
10-
async getAllDonations(): Promise<Array<DonationDTO>> {
11-
try {
12-
const allDonations = await prisma.donation.findMany();
13-
14-
return allDonations;
15-
} catch (error) {
16-
Logger.error(`Error fetching donations. Reason = ${getErrorMessage(error)}`);
17-
throw error;
18-
}
10+
async getAllDonations(): Promise<Array<DonationDTO>> {
11+
try {
12+
const allDonations = await prisma.donation.findMany();
13+
14+
return allDonations;
15+
} catch (error) {
16+
Logger.error(
17+
`Error fetching donations. Reason = ${getErrorMessage(error)}`,
18+
);
19+
throw error;
20+
}
21+
}
22+
23+
async getUserDonation(user_id: string): Promise<Array<DonationDTO>> {
24+
console.log(user_id);
25+
try {
26+
const userDonations = await prisma.donation.findMany({
27+
where: {
28+
user_id,
29+
},
30+
});
31+
32+
return userDonations;
33+
} catch (error) {
34+
Logger.error(`Error fetching donation for user ${user_id} = ${error}`);
35+
throw error;
1936
}
37+
}
2038

21-
async getUserDonation(user_id: string): Promise<Array<DonationDTO>> {
22-
console.log(user_id);
39+
async createDonation(
40+
user_id: string,
41+
amount: number,
42+
cause_id: number,
43+
is_recurring: string,
44+
confirmation_email_sent: boolean,
45+
): Promise<DonationDTO> {
46+
{
2347
try {
24-
const userDonations = await prisma.donation.findMany({
25-
where: {
26-
user_id: user_id,
27-
}
48+
const newDonation = await prisma.donation.create({
49+
data: {
50+
user_id,
51+
amount,
52+
donation_date: new Date(),
53+
cause_id,
54+
is_recurring: is_recurring as Recurrence,
55+
confirmation_email_sent,
56+
},
2857
});
29-
30-
return userDonations;
58+
return newDonation;
3159
} catch (error) {
32-
Logger.error(`Error fetching donation for user ${user_id} = ${error}`);
60+
Logger.error(`Error creating donation for user ${user_id} = ${error}`);
3361
throw error;
3462
}
3563
}
36-
37-
async createDonation(user_id: string, amount: number, cause_id: number, is_recurring: string, confirmation_email_sent: boolean): Promise<DonationDTO> {
38-
{
39-
try {
40-
const newDonation = await prisma.donation.create({
41-
data: {
42-
user_id: user_id,
43-
amount,
44-
donation_date: new Date(),
45-
cause_id: cause_id,
46-
is_recurring: is_recurring as Recurrence,
47-
confirmation_email_sent
48-
},
49-
});
50-
return newDonation;
51-
} catch (error) {
52-
Logger.error(`Error creating donation for user ${user_id} = ${error}`);
53-
throw error;
54-
}
55-
}
56-
}
64+
}
5765
}
5866

59-
export default DonationService;
67+
export default DonationService;

backend/typescript/services/implementations/userService.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,12 @@ class UserService implements IUserService {
287287
async deleteUserById(userId: string): Promise<void> {
288288
try {
289289
// Sequelize doesn't provide a way to atomically find, delete, and return deleted row
290-
const deletedUser: Prisma.UserCreateInput | null = await prisma.user.findUnique(
291-
{
290+
const deletedUser: Prisma.UserCreateInput | null =
291+
await prisma.user.findUnique({
292292
where: {
293293
id: String(userId),
294294
},
295-
},
296-
);
295+
});
297296

298297
if (!deletedUser) {
299298
throw new Error(`userid ${userId} not found.`);
@@ -343,13 +342,12 @@ class UserService implements IUserService {
343342
const firebaseUser: firebaseAdmin.auth.UserRecord = await firebaseAdmin
344343
.auth()
345344
.getUserByEmail(email);
346-
const deletedUser: Prisma.UserCreateInput | null = await prisma.user.findFirst(
347-
{
345+
const deletedUser: Prisma.UserCreateInput | null =
346+
await prisma.user.findFirst({
348347
where: {
349348
auth_id: firebaseUser.uid,
350349
},
351-
},
352-
);
350+
});
353351

354352
if (!deletedUser) {
355353
throw new Error(`userid ${firebaseUser.uid} not found.`);
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
import { DonationDTO, Recurrence } from "../../types";
22

33
interface IDonationService {
4-
/**
5-
* Get all donations across all users
6-
* @returns an array of DonationDTO
7-
* @throws Error if donation retrieval fails
8-
*/
9-
getAllDonations(): Promise<Array<DonationDTO>>;
4+
/**
5+
* Get all donations across all users
6+
* @returns an array of DonationDTO
7+
* @throws Error if donation retrieval fails
8+
*/
9+
getAllDonations(): Promise<Array<DonationDTO>>;
1010

11-
/**
12-
* Get all donations associated with user_id
13-
* @param user_id user's id
14-
* @returns an array of DonationDTO
15-
* @throws Error if donation retrieval fails
16-
*/
17-
getUserDonation(user_id: string): Promise<Array<DonationDTO>>;
11+
/**
12+
* Get all donations associated with user_id
13+
* @param user_id user's id
14+
* @returns an array of DonationDTO
15+
* @throws Error if donation retrieval fails
16+
*/
17+
getUserDonation(user_id: string): Promise<Array<DonationDTO>>;
1818

19-
/**
20-
* Create a donation
21-
* @param user_id user's id
22-
* @param amount the amount the user is donating toward this cause in the donation
23-
* @param cause_id the id of the cause the donation is associated with
24-
* @param is_recurring whether or not the donation is reoccurring
25-
* @param confirmation_email_sent whether or not a confirmation email has been sent
26-
* @returns the newly created DonationDTO
27-
* @throws Error if donation cannot be created
28-
*/
29-
createDonation(
30-
user_id: string,
31-
amount: number,
32-
cause_id: number,
33-
is_recurring: string,
34-
confirmation_email_sent: boolean
35-
): Promise<DonationDTO>;
19+
/**
20+
* Create a donation
21+
* @param user_id user's id
22+
* @param amount the amount the user is donating toward this cause in the donation
23+
* @param cause_id the id of the cause the donation is associated with
24+
* @param is_recurring whether or not the donation is reoccurring
25+
* @param confirmation_email_sent whether or not a confirmation email has been sent
26+
* @returns the newly created DonationDTO
27+
* @throws Error if donation cannot be created
28+
*/
29+
createDonation(
30+
user_id: string,
31+
amount: number,
32+
cause_id: number,
33+
is_recurring: string,
34+
confirmation_email_sent: boolean,
35+
): Promise<DonationDTO>;
3636
}
3737

3838
export default IDonationService;

backend/typescript/testUtils/testDb.ts

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { resolve } from "path";
22

33
import { Sequelize } from "sequelize-typescript";
44

5-
65
const DATABASE_URL =
76
process.env.NODE_ENV === "production"
87
? /* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */

backend/typescript/types.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { DateDataType } from "sequelize";
2-
import { FloatDataType, IntegerDataType } from "sequelize";
1+
import { DateDataType, FloatDataType, IntegerDataType } from "sequelize";
32

43
export type Role = "User" | "Admin";
54

@@ -48,6 +47,6 @@ export type DonationDTO = {
4847
cause_id: number;
4948
is_recurring: Recurrence;
5049
confirmation_email_sent: boolean;
51-
}
50+
};
5251

5352
export type CreateDonationDTO = Omit<DonationDTO, "user_id">;

0 commit comments

Comments
 (0)