Skip to content

Commit ab72965

Browse files
author
DylanBulmer
committed
update user and profile models
1 parent f1b43ef commit ab72965

5 files changed

Lines changed: 25 additions & 17 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codrjs/core",
3-
"version": "1.0.9",
3+
"version": "1.0.10",
44
"description": "An open-sourced customizable annotation tool",
55
"main": "./cjs/index.js",
66
"module": "./esm/index.js",

src/models/Profile.ability.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ export default function ProfileAbility(user: IUser) {
66
if (user.role === "codr:admin") {
77
can("manage", "Profile");
88
} else {
9-
can("create", "Profile", { userId: user._id });
10-
can("read", "Profile", { userId: user._id });
11-
can("update", "Profile", { userId: user._id });
9+
can("create", "Profile", { user: user._id });
10+
can("read", "Profile", { user: user._id });
11+
can("update", "Profile", { user: user._id });
1212
}
1313
});
1414
}

src/models/Profile.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ import {
66
import { Schema, model, Document } from "mongoose";
77

88
export interface IProfile extends Document {
9+
avatarUrl?: string;
910
username: string;
10-
userId: Schema.Types.ObjectId;
11+
user: Schema.Types.ObjectId;
1112
}
1213

1314
const ProfileSchema = new Schema<IProfile>(
1415
{
1516
username: { type: String, required: true, unique: true },
16-
userId: {
17+
avatarUrl: { type: String },
18+
user: {
1719
type: Schema.Types.ObjectId,
1820
ref: "User",
1921
required: true,

src/models/User.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export interface IUser extends Document {
3030
providers?: IUserProvider;
3131
isAdmin: boolean;
3232
role: UserRoleType;
33+
disabled: boolean;
34+
anonymous: boolean;
3335
}
3436

3537
const UserProvider = new Schema<IUserProvider>({
@@ -74,6 +76,14 @@ const UserSchema = new Schema<IUser>(
7476
type: String,
7577
required: [true, "Please specify the user's role."],
7678
},
79+
disabled: {
80+
type: Boolean,
81+
default: false,
82+
},
83+
anonymous: {
84+
type: Boolean,
85+
default: false,
86+
},
7787
},
7888
{
7989
timestamps: true,

src/services/database.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import ProfileAbility from "../models/Profile.ability.js";
77
import User, { IUser } from "../models/User.js";
88
import UserAbility from "../models/User.ability.js";
99
import App from "./app.js";
10-
import { QueryWithHelpers, Types } from "mongoose";
10+
import { QueryWithHelpers } from "mongoose";
1111
import type { AccessibleRecordQueryHelpers } from "@casl/mongoose/dist/types/accessible_records.js";
1212
import Error from "../classes/Error.js";
1313

@@ -33,17 +33,13 @@ class Database {
3333
}
3434
}
3535

36-
Profile(token: IUser): QueryWithHelpers<
37-
(IProfile & {
38-
_id: Types.ObjectId;
39-
})[],
40-
IProfile & {
41-
_id: Types.ObjectId;
42-
},
36+
Profile(
37+
token: IUser,
38+
): QueryWithHelpers<
39+
IProfile[],
40+
IProfile,
4341
AccessibleRecordQueryHelpers<IProfile>,
44-
IProfile & {
45-
_id: Types.ObjectId;
46-
}
42+
IProfile
4743
> {
4844
if (this.app.mongoIsConnected)
4945
return Profile.accessibleBy(ProfileAbility(token));

0 commit comments

Comments
 (0)