Skip to content

Commit

Permalink
feat(RL-78): login syncs with bookmarks;
Browse files Browse the repository at this point in the history
  • Loading branch information
NoodleOfDeath committed Nov 10, 2023
1 parent c6c02f2 commit abf6a63
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/server/src/api/v1/schema/user/User.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,13 @@ export class User<A extends UserAttributes = UserAttributes, B extends UserCreat
if (aliases.length === 0) {
throw new AuthError('UNKNOWN_ALIAS');
}
const metadata = await UserMetadata.findAll({ where: { userId: this.id } });
const updatedAt = new Date(Math.max(...[...aliases, ...metadata].map((m) => m.updatedAt.valueOf())));
const profile: Profile = {
email: aliases.sort((a, b) => a.priority - b.priority)[0].value,
emails: aliases.map((a) => a.value),
preferences: Object.fromEntries((await UserMetadata.findAll({ where: { userId: this.id } })).map((meta) => [meta.key, typeof meta.value === 'string' ? JSON.parse(meta.value) : meta.value])),
preferences: Object.fromEntries(metadata.map((meta) => [meta.key, typeof meta.value === 'string' ? JSON.parse(meta.value) : meta.value])),
updatedAt,
username: (await this.findAlias('username'))?.value,
};
this.set('profile', profile, { raw: true });
Expand Down
1 change: 1 addition & 0 deletions src/server/src/api/v1/schema/user/User.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type Profile = {
firstName?: string;
lastName?: string;
preferences?: { [key: string]: unknown };
updatedAt?: Date;
};

export type UserAttributes = DatedAttributes & {
Expand Down

0 comments on commit abf6a63

Please sign in to comment.