Skip to content

Commit dc9c6bd

Browse files
author
DylanBulmer
committed
update abac implementation
1 parent e859e08 commit dc9c6bd

18 files changed

Lines changed: 82 additions & 66 deletions

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codrjs/models",
3-
"version": "1.0.10",
3+
"version": "1.0.11",
44
"description": "",
55
"main": "./cjs/index.js",
66
"module": "./esm/index.js",

src/entities/Annotation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Types } from "mongoose";
22
import { Base, IBaseMinimal } from "./Base";
33

44
export interface IAnnotation extends IBaseMinimal {
5+
readonly kind: "Annotation";
56
projectId: Types.ObjectId;
67
datasetId: Types.ObjectId;
78
sampleId: Types.ObjectId;

src/entities/Audit.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { IBaseMinimal } from "./Base";
33
import type { ActionType, EntityType } from "../types";
44

55
export interface IAudit extends Omit<IBaseMinimal, "createdBy"> {
6+
readonly kind: "Audit";
67
entityType: EntityType; // (where) what entity got modified
78
action: ActionType; // action taken
89
userId: Types.ObjectId; // who

src/entities/Base.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ import { Types } from "mongoose";
22
import { AtLeast } from "../types";
33

44
export interface IBase {
5+
readonly kind: string;
56
__v?: number;
67
_id: Types.ObjectId;
7-
createdAt: string;
8-
updatedAt: string;
8+
createdAt: Date;
9+
updatedAt: Date;
910
createdBy: Types.ObjectId;
1011
updatedBy: Types.ObjectId;
1112
}
1213

13-
export type IBaseMinimal = AtLeast<IBase, 'createdBy'>
14+
export type IBaseMinimal = AtLeast<IBase, "createdBy">;
1415

1516
export class Base {
1617
readonly __v: IBase["__v"];
@@ -31,9 +32,9 @@ export class Base {
3132
this.__v = __v;
3233
this._id = _id || new Types.ObjectId();
3334

34-
const now = Date.now();
35-
this.createdAt = new Date(createdAt || now);
36-
this.updatedAt = new Date(updatedAt || now);
35+
const now = new Date(Date.now());
36+
this.createdAt = createdAt || now;
37+
this.updatedAt = updatedAt || now;
3738

3839
this.createdBy = createdBy;
3940
this.updatedBy = updatedBy || createdBy;
@@ -43,8 +44,8 @@ export class Base {
4344
return {
4445
__v: this.__v,
4546
_id: this._id,
46-
createdAt: this.createdAt.toISOString(),
47-
updatedAt: this.updatedAt.toISOString(),
47+
createdAt: this.createdAt,
48+
updatedAt: this.updatedAt,
4849
createdBy: this.createdBy,
4950
updatedBy: this.updatedBy,
5051
};

src/entities/Config/BaseConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Base, IBaseMinimal } from "../Base";
22

33
export interface IBaseConfig extends IBaseMinimal {
4+
readonly kind: "Config";
45
verison?: string;
56
flags?: { isDeleted: boolean };
67
}

src/entities/Config/Project/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import BaseConfig, { IBaseConfig } from "../BaseConfig";
22
import { DisplayConfig } from "./types/Display";
33
import { SampleConfig } from "./types/Sample";
44

5-
export interface IProjectConfig extends IBaseConfig {
5+
export interface IProjectConfig extends Omit<IBaseConfig, "kind"> {
66
// $schema: string;
77
display: DisplayConfig;
88
sample: SampleConfig;
@@ -26,6 +26,7 @@ export default class ProjectConfig extends BaseConfig {
2626
sample,
2727
}: IProjectConfig) {
2828
super({
29+
kind: 'Config',
2930
verison,
3031
flags,
3132
_id,

src/entities/Dataset.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Group, IGroup } from "./Group";
33

44
// eslint-disable-next-line @typescript-eslint/no-empty-interface
55
export interface IDataset extends IGroup {
6+
readonly kind: "Dataset";
67
projectId: Types.ObjectId;
78
}
89

src/entities/Message.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { MessageType } from "../types";
33
import { Base, IBaseMinimal } from "./Base";
44

55
export interface IMessage extends IBaseMinimal {
6+
readonly kind: "Message";
67
type: MessageType;
78
subject: string;
89
body: string;

src/entities/Profile.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import type { Types } from "mongoose";
22
import { Base, IBaseMinimal } from "./Base";
3+
import { User } from "./User";
34

45
export interface IProfile extends IBaseMinimal {
6+
readonly kind: "Profile";
57
name: {
68
first: string;
79
last: string;
@@ -23,6 +25,7 @@ export class Profile extends Base {
2325
avatarUrl?: string;
2426
username: string;
2527
userId: Types.ObjectId;
28+
user?: User;
2629

2730
constructor({
2831
name,
@@ -32,17 +35,19 @@ export class Profile extends Base {
3235
phone,
3336
_id,
3437
__v,
38+
user,
3539
createdAt,
3640
updatedAt,
3741
createdBy,
3842
updatedBy,
39-
}: IProfile) {
43+
}: IProfile & { user?: User }) {
4044
super({ _id, __v, createdAt, updatedAt, createdBy, updatedBy });
4145
this.name = name;
4246
this.avatarUrl = avatarUrl;
4347
this.userId = userId;
4448
this.phone = phone;
4549
this.username = username;
50+
this.user = user;
4651
}
4752

4853
toJSON() {

src/entities/Project.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Flags, TaskType } from "../types";
33
import { Base, IBaseMinimal } from "./Base";
44

55
export interface IProject extends IBaseMinimal {
6+
readonly kind: "Project";
67
name: string;
78
type: TaskType;
89
slug: string;

0 commit comments

Comments
 (0)