Skip to content

Commit

Permalink
BACKEND-4: Add users model
Browse files Browse the repository at this point in the history
  • Loading branch information
vinnie4k committed Sep 10, 2024
1 parent 1bb0c0a commit 39acce4
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/announcements/examples.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
8 changes: 8 additions & 0 deletions src/announcements/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import {
prop,
modelOptions,
Severity,
Ref,
} from "@typegoose/typegoose";
import { User } from "../users/models";

@modelOptions({
schemaOptions: {
Expand All @@ -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<User>;

@prop()
public endDate!: Date;

Expand Down
19 changes: 19 additions & 0 deletions src/users/examples.ts
Original file line number Diff line number Diff line change
@@ -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: "[email protected]",
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: "[email protected]",
name: "Lauren Jun",
};

export const exampleUsers = [exampleUser1, exampleUser2];
34 changes: 34 additions & 0 deletions src/users/models.ts
Original file line number Diff line number Diff line change
@@ -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);
Empty file added src/users/routes.ts
Empty file.
Empty file added src/users/services.ts
Empty file.
Empty file added src/users/types.ts
Empty file.

0 comments on commit 39acce4

Please sign in to comment.