From 39acce46598c7ed5436b2699aa50429e407c2a8c Mon Sep 17 00:00:00 2001 From: Vin Bui Date: Tue, 10 Sep 2024 10:53:48 -0400 Subject: [PATCH] BACKEND-4: Add users model --- src/announcements/examples.ts | 3 +++ src/announcements/models.ts | 8 ++++++++ src/users/examples.ts | 19 +++++++++++++++++++ src/users/models.ts | 34 ++++++++++++++++++++++++++++++++++ src/users/routes.ts | 0 src/users/services.ts | 0 src/users/types.ts | 0 7 files changed, 64 insertions(+) create mode 100644 src/users/examples.ts create mode 100644 src/users/models.ts create mode 100644 src/users/routes.ts create mode 100644 src/users/services.ts create mode 100644 src/users/types.ts diff --git a/src/announcements/examples.ts b/src/announcements/examples.ts index 4b273a0..b9b4727 100644 --- a/src/announcements/examples.ts +++ b/src/announcements/examples.ts @@ -1,7 +1,10 @@ +import { exampleUser1 } from "../users/examples"; + export const exampleAnnouncement = { id: "6645282bdc295809ab5c0c28", apps: ["eatery", "transit", "uplift", "coursegrab", "volume", "resell"], body: "Pizza will be provided. Come and see us! We would love to speak with you!", + creator: exampleUser1, endDate: "2024-08-16T03:00:00Z", imageUrl: "https://appdev-upload.nyc3.digitaloceanspaces.com/announcements/pc6k6o8z.png", diff --git a/src/announcements/models.ts b/src/announcements/models.ts index 85439ae..835dc35 100644 --- a/src/announcements/models.ts +++ b/src/announcements/models.ts @@ -3,7 +3,9 @@ import { prop, modelOptions, Severity, + Ref, } from "@typegoose/typegoose"; +import { User } from "../users/models"; @modelOptions({ schemaOptions: { @@ -24,6 +26,12 @@ export class Announcement { @prop() public body!: string; + /** + * @ignore See https://github.com/lukeautry/tsoa/issues/626. + */ + @prop({ ref: () => User }) + public creator?: Ref; + @prop() public endDate!: Date; diff --git a/src/users/examples.ts b/src/users/examples.ts new file mode 100644 index 0000000..4bbf9c8 --- /dev/null +++ b/src/users/examples.ts @@ -0,0 +1,19 @@ +export const exampleUser1 = { + id: "65f3c6c85ec12921d8bbd0e3", + isAdmin: true, + imageUrl: + "https://media.licdn.com/dms/image/v2/D5603AQHN8gWRzyN-3g/profile-displayphoto-shrink_800_800/profile-displayphoto-shrink_800_800/0/1710110275806?e=1731542400&v=beta&t=8XE8qDedoImTZo1QhvletOkhHasb31BCT4MBuj2OLkY", + email: "vdb23@cornell.edu", + name: "Vin Bui", +}; + +export const exampleUser2 = { + id: "65f3c6c85ec12921d8bbd0e4", + isAdmin: false, + imageUrl: + "https://media.licdn.com/dms/image/v2/D4E03AQGe3o27d-Y5Eg/profile-displayphoto-shrink_800_800/profile-displayphoto-shrink_800_800/0/1725558867182?e=1731542400&v=beta&t=JatU-XhdnisKyaWefPALJdB-3lU44C1RtkXY-uhPs6A", + email: "lj295@cornell.edu", + name: "Lauren Jun", +}; + +export const exampleUsers = [exampleUser1, exampleUser2]; diff --git a/src/users/models.ts b/src/users/models.ts new file mode 100644 index 0000000..17baf35 --- /dev/null +++ b/src/users/models.ts @@ -0,0 +1,34 @@ +import { + getModelForClass, + prop, + modelOptions, + Severity, +} from "@typegoose/typegoose"; + +@modelOptions({ + schemaOptions: { + toJSON: { + virtuals: true, + versionKey: false, + transform: function (doc, ret) { + delete ret._id; + }, + }, + }, + options: { allowMixed: Severity.ALLOW }, +}) +export class User { + @prop({ unique: true }) + public email!: string; + + @prop() + public imageUrl!: string; + + @prop({ default: false }) + public isAdmin!: boolean; + + @prop() + public name!: string; +} + +export const UserModel = getModelForClass(User); diff --git a/src/users/routes.ts b/src/users/routes.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/users/services.ts b/src/users/services.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/users/types.ts b/src/users/types.ts new file mode 100644 index 0000000..e69de29