Skip to content

Commit

Permalink
Add typing to database
Browse files Browse the repository at this point in the history
  • Loading branch information
AydanPirani committed May 29, 2024
1 parent 48cfaad commit cee2182
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
26 changes: 13 additions & 13 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ export const Config = {
"https://api.reflectionsprojections.org/auth/callback/",

AUTH_ADMIN_WHITELIST: new Set([
"[email protected]", // Aydan Pirani (Dev)
"[email protected]" // Divya Koya (Dev)
"[email protected]", // Aryan Bahl (Dev)
"[email protected]", // Alex Yang (Dev)
"[email protected]", // Aryan Bhardwaj (Dev)
"[email protected]", // Dev Patel (Dev)
"[email protected]", // Divya Koya (Dev)
"[email protected]", // Jacob Chang (Dev)
"[email protected]", // Jeremy Wu (Dev)
"[email protected]", // Manya Dua (Dev)
"[email protected]", // Riya Patel (Dev)
"[email protected]", // Ronit Anandani (Dev)
"[email protected]", // Shreenija Reddy Daggavolu (Dev)
"[email protected]", // Aydan Pirani (Dev)
"[email protected]", // Divya Koya (Dev)
"[email protected]", // Aryan Bahl (Dev)
"[email protected]", // Alex Yang (Dev)
"[email protected]", // Aryan Bhardwaj (Dev)
"[email protected]", // Dev Patel (Dev)
"[email protected]", // Divya Koya (Dev)
"[email protected]", // Jacob Chang (Dev)
"[email protected]", // Jeremy Wu (Dev)
"[email protected]", // Manya Dua (Dev)
"[email protected]", // Riya Patel (Dev)
"[email protected]", // Ronit Anandani (Dev)
"[email protected]", // Shreenija Reddy Daggavolu (Dev)
]),

JWT_SIGNING_SECRET: getEnv("JWT_SIGNING_SECRET"),
Expand Down
6 changes: 4 additions & 2 deletions src/database.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mongoose, { Schema } from "mongoose";
import mongoose, { Schema, Document } from "mongoose";
import {
AttendeeSchema,
AttendeeValidator,
Expand Down Expand Up @@ -43,7 +43,9 @@ function initializeModel(
},
});

return mongoose.model(modelName, schema);
type objectType = Zod.infer<typeof object>;
interface modelType extends Document, objectType {}
return mongoose.model<modelType>(modelName, schema);
}

// Example usage
Expand Down
4 changes: 2 additions & 2 deletions src/services/auth/auth-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ export function createGoogleStrategy(device: string) {
const name = profile.displayName;
const email = profile._json.email;
const roles = [];

// Check if user is admin -> if so, add ADMIN role to their list
if (Config.AUTH_ADMIN_WHITELIST.has(email ?? "")) {
roles.push(Role.Enum.ADMIN);
}

Database.ROLES.findOneAndUpdate(
{ userId: userId },
{ userId, name, email, roles },
Expand Down

0 comments on commit cee2182

Please sign in to comment.