generated from CodrJS/ts-npm-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement user domain; fine-tune user entity
- Loading branch information
DylanBulmer
committed
Jun 18, 2023
1 parent
8141b49
commit 9540983
Showing
20 changed files
with
153 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/types/NotificationDatabase.ts → src/types/Database/Notification.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { AccessibleModel } from "@casl/mongoose"; | ||
import { DatabaseEnum } from "."; | ||
import { ProfileDocument } from "@/schemas/Profile"; | ||
import { SessionDocument } from "@/schemas/Session"; | ||
import { UserGroupDocument } from "@/schemas/UserGroup"; | ||
import { UserDocument } from "@/schemas/User"; | ||
|
||
export enum UserModelEnum { | ||
PROFILE = "Profile", | ||
SESSION = "Session", | ||
USERGROUP = "UserGroup", | ||
USER = "User", | ||
} | ||
export type UserModelType = keyof typeof UserModelEnum; | ||
export type UserModels = `${UserModelEnum}`; | ||
|
||
export interface DatabaseUserConfig { | ||
name: DatabaseEnum.USER; | ||
models: UserModels[]; | ||
} | ||
|
||
export interface ILoadedUserModels<T extends UserModels> { | ||
Profile: T extends "Profile" ? AccessibleModel<ProfileDocument> : never; | ||
Session: T extends "Session" ? AccessibleModel<SessionDocument> : never; | ||
UserGroup: T extends "UserGroup" ? AccessibleModel<UserGroupDocument> : never; | ||
User: AccessibleModel<UserDocument>; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export type MongooseConnectionEvent = | ||
| "open" | ||
| "close" | ||
| "reconnected" | ||
| "disconnected"; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export * from "./CoreDatabase"; | ||
export * from "./Database"; | ||
export * from "./NotificationDatabase"; | ||
export * from "./ProjectDatabase"; | ||
export * from "./UserDatabase"; | ||
export * from "./Database/Core"; | ||
export * from "./Database/Notification"; | ||
export * from "./Database/Project"; | ||
export * from "./Database/User"; | ||
export * from "./MongooseEvent"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,42 @@ | ||
import { createProfileModel } from "@/schemas/Profile"; | ||
import { createSessionModel } from "@/schemas/Session"; | ||
import UserSchema from "@/schemas/User"; | ||
import { createUserGroupModel } from "@/schemas/UserGroup"; | ||
import { UserModelEnum, UserModels } from "@/types"; | ||
import { ProfileDocument, createProfileModel } from "@/schemas/Profile"; | ||
import { SessionDocument, createSessionModel } from "@/schemas/Session"; | ||
import UserSchema, { UserDocument } from "@/schemas/User"; | ||
import { UserGroupDocument, createUserGroupModel } from "@/schemas/UserGroup"; | ||
import { ILoadedUserModels, UserModelEnum, UserModels } from "@/types"; | ||
import { AccessibleModel } from "@casl/mongoose"; | ||
import { IProfile, ISession, IUser, IUserGroup } from "@codrjs/models"; | ||
import mongoose from "mongoose"; | ||
import type { Connection } from "mongoose"; | ||
|
||
export default function userDatabaseSetup( | ||
database: mongoose.Connection, | ||
database: Connection, | ||
use: Record<UserModels, boolean>, | ||
loaded: Record<UserModels, AccessibleModel<any>>, | ||
loaded: ILoadedUserModels<UserModels>, | ||
) { | ||
// add model only if needed. | ||
if (use.User) { | ||
loaded.User = database.model<IUser, AccessibleModel<IUser>>( | ||
loaded.User = database.model<UserDocument, AccessibleModel<UserDocument>>( | ||
UserModelEnum.USER, | ||
UserSchema, | ||
); | ||
} | ||
|
||
if (use.Profile) { | ||
loaded.Profile = database.model<IProfile, AccessibleModel<IProfile>>( | ||
UserModelEnum.PROFILE, | ||
createProfileModel(loaded.User), | ||
); | ||
loaded.Profile = database.model< | ||
ProfileDocument, | ||
AccessibleModel<ProfileDocument> | ||
>(UserModelEnum.PROFILE, createProfileModel(loaded.User)); | ||
} | ||
|
||
if (use.Session) { | ||
loaded.Session = database.model<ISession, AccessibleModel<ISession>>( | ||
UserModelEnum.SESSION, | ||
createSessionModel(loaded.User), | ||
); | ||
loaded.Session = database.model< | ||
SessionDocument, | ||
AccessibleModel<SessionDocument> | ||
>(UserModelEnum.SESSION, createSessionModel(loaded.User)); | ||
} | ||
|
||
if (use.UserGroup) { | ||
loaded.UserGroup = database.model< | ||
IUserGroup, | ||
AccessibleModel<IUserGroup> | ||
UserGroupDocument, | ||
AccessibleModel<UserGroupDocument> | ||
>(UserModelEnum.USERGROUP, createUserGroupModel(loaded.User)); | ||
} | ||
} |
Oops, something went wrong.