Skip to content

Commit

Permalink
update user model
Browse files Browse the repository at this point in the history
  • Loading branch information
Lisa18289 committed Sep 19, 2024
1 parent 1c9f0f5 commit 3270671
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions packages/models/src/user/User/User.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { ReferenceModel } from "../../base/ReferenceModel.js";
import {
type AsyncResourceVariant,
provideReact,
} from "../../lib/provideReact.js";
import { config } from "../../config/config.js";
import { DataModel } from "../../base/DataModel.js";
import { classes } from "polytype";
import {
UserAuthenticateMfaRequestData,
Expand All @@ -27,6 +25,7 @@ import {
UserVerifyRegistrationRequestData,
} from "./types.js";
import assertObjectFound from "../../base/assertObjectFound.js";
import { DataModel, ReferenceModel } from "../../base/index.js";

export class User extends ReferenceModel {
public static ofId(id: string): User {
Expand All @@ -36,7 +35,6 @@ export class User extends ReferenceModel {
public static find = provideReact(
async (id: string): Promise<UserDetailed | undefined> => {
const data = await config.behaviors.user.find(id);

if (data !== undefined) {
return new UserDetailed(data);
}
Expand All @@ -46,9 +44,7 @@ export class User extends ReferenceModel {
public static get = provideReact(
async (id: string): Promise<UserDetailed> => {
const user = await this.find(id);

assertObjectFound(user, this, id);

return user;
},
);
Expand All @@ -57,10 +53,16 @@ export class User extends ReferenceModel {
return await this.get("self");
});

public getDetailed = provideReact(() =>
User.get(this.id),
public getDetailed = provideReact(
() => User.get(this.id),
[this.id],
) as AsyncResourceVariant<UserDetailed, []>;

public findDetailed = provideReact(
() => User.find(this.id),
[this.id],
) as AsyncResourceVariant<UserDetailed | undefined, []>;

public getPasswordUpdatedAt = provideReact(
async (): Promise<{ passwordUpdatedAt: string }> => {
return await config.behaviors.user.getPasswordUpdatedAt();
Expand Down

0 comments on commit 3270671

Please sign in to comment.