ah
This commit is contained in:
parent
39ba4856a2
commit
e86d909e07
@ -7,19 +7,20 @@ import {
|
|||||||
UserWithPasswordCtor,
|
UserWithPasswordCtor,
|
||||||
} from '@core';
|
} from '@core';
|
||||||
import { getHashedPassword } from '../functions/password';
|
import { getHashedPassword } from '../functions/password';
|
||||||
|
import { Card } from './card';
|
||||||
import { Entity } from './entity';
|
import { Entity } from './entity';
|
||||||
|
|
||||||
export class User extends Entity implements UserInfo {
|
export class User extends Entity implements UserInfo {
|
||||||
username: string;
|
username: string;
|
||||||
role: keyof typeof UserRoles;
|
role: keyof typeof UserRoles;
|
||||||
cards: CardInfo[];
|
cards: Card[];
|
||||||
|
|
||||||
constructor(raw: UserCtor) {
|
constructor(raw: UserCtor) {
|
||||||
super(raw);
|
super(raw);
|
||||||
|
|
||||||
this.username = raw.username || '';
|
this.username = raw.username || '';
|
||||||
this.role = raw.role || UserRoles.USER;
|
this.role = raw.role || UserRoles.USER;
|
||||||
this.cards = this.cards || '';
|
this.cards = raw.cards ? raw.cards.map(card => new Card(card)) : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
Info(): UserInfo {
|
Info(): UserInfo {
|
||||||
@ -27,7 +28,7 @@ export class User extends Entity implements UserInfo {
|
|||||||
uuid: this.uuid,
|
uuid: this.uuid,
|
||||||
username: this.username,
|
username: this.username,
|
||||||
role: this.role,
|
role: this.role,
|
||||||
cards: this.cards,
|
cards: this.cards.map(card => card.Info()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -46,7 +47,7 @@ export class UserWithPassword extends User implements UserInfoWithPassword {
|
|||||||
uuid: this.uuid,
|
uuid: this.uuid,
|
||||||
username: this.username,
|
username: this.username,
|
||||||
role: this.role,
|
role: this.role,
|
||||||
cards: this.cards,
|
cards: this.cards.map(card => card.Info()),
|
||||||
password: this.password,
|
password: this.password,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Collection, Db } from 'mongodb';
|
import { Collection, Db } from 'mongodb';
|
||||||
import { Card, CardInfo, LoginUserBody, UpdateUserBody } from '@core';
|
import { Card, CardInfo, LoginUserBody, UpdateUserBody, UserInfo } from '@core';
|
||||||
import { User, UserWithPassword } from '../../entities/user';
|
import { User, UserWithPassword } from '../../entities/user';
|
||||||
import { log } from '../../functions/logger';
|
import { log } from '../../functions/logger';
|
||||||
import { getHashedPassword } from '../../functions/password';
|
import { getHashedPassword } from '../../functions/password';
|
||||||
@ -54,7 +54,22 @@ class UserModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async read(tracker: string, uuid: string): Promise<User> {
|
public async read(tracker: string, uuid: string): Promise<User> {
|
||||||
const userDocument = await this.collection.findOne({ uuid });
|
const [userDocument] = await this.collection.aggregate<UserInfo>([
|
||||||
|
{
|
||||||
|
$match:{
|
||||||
|
uuid
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$lookup: {
|
||||||
|
from: "cards",
|
||||||
|
localField: "cards",
|
||||||
|
foreignField: "_id",
|
||||||
|
as: "cards"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]).toArray();
|
||||||
|
console.log(JSON.stringify(userDocument));
|
||||||
if (!userDocument) {
|
if (!userDocument) {
|
||||||
log(tracker, 'User Not Found');
|
log(tracker, 'User Not Found');
|
||||||
throw new Error();
|
throw new Error();
|
||||||
@ -118,7 +133,7 @@ class UserModel {
|
|||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
},
|
},
|
||||||
$addToSet: {
|
$addToSet: {
|
||||||
cards: card,
|
cards: card._id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user