Skip to content

Commit

Permalink
add email field and get for sponsors
Browse files Browse the repository at this point in the history
  • Loading branch information
caupcakes committed Aug 12, 2024
1 parent fa205e1 commit 672a5f4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/services/auth/auth-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Role } from "../auth/auth-models";
import { AuthRoleChangeRequest } from "./auth-schema";
import { z } from "zod";
import authSponsorRouter from "./sponsor/sponsor-router";
import { CorporateDeleteRequest, CorporateValidator } from "./corporate-schema";

const authStrategies: Record<string, GoogleStrategy> = {};

Expand Down Expand Up @@ -165,27 +166,43 @@ authRouter.get(
}
);

authRouter.get(
"/corporate",
RoleChecker([Role.Enum.ADMIN], true),
async (req, res, next) => {
try {
const allCorporate = await Database.CORPORATE.find();

return res.sendStatus(StatusCodes.OK).json(allCorporate);
} catch (error) {
next(error);
}
}
);

authRouter.post(
"/corporate/:email",
"/corporate",
RoleChecker([Role.Enum.ADMIN], true),
async (req, res, next) => {
try {
const email = req.params.email;
const corporate = new Database.CORPORATE({ email: email });
const attendeeData = CorporateValidator.parse(req.body);
const corporate = new Database.CORPORATE(attendeeData);
await corporate.save();
return res.status(StatusCodes.CREATED).json(email);

return res.status(StatusCodes.CREATED).json(corporate);
} catch (error) {
next(error);
}
}
);

authRouter.delete(
"/corporate/:email",
"/corporate",
RoleChecker([Role.Enum.ADMIN], true),
async (req, res, next) => {
try {
const email = req.params.email;
const attendeeData = CorporateDeleteRequest.parse(req.body);
const email = attendeeData.email;
await Database.CORPORATE.findOneAndDelete({ email: email });

return res.sendStatus(StatusCodes.NO_CONTENT);
Expand Down
10 changes: 10 additions & 0 deletions src/services/auth/corporate-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@ import { z } from "zod";

// Zod schema
export const CorporateValidator = z.object({
name: z.string(),
email: z.string(),
});

// Zod schema
export const CorporateDeleteRequest = z.object({
email: z.string(),
});

// Mongoose schema
export const CorporateSchema = new Schema({
name: {
type: String,
required: true

Check failure on line 19 in src/services/auth/corporate-schema.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
},
email: {
type: String,
required: true,
Expand Down

0 comments on commit 672a5f4

Please sign in to comment.