Skip to content

Commit

Permalink
Merge branch 'master' into feat/rm-command
Browse files Browse the repository at this point in the history
  • Loading branch information
Huy-DNA committed Nov 5, 2024
2 parents 143703d + 99f9d05 commit cc293b9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
21 changes: 13 additions & 8 deletions services/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,24 @@ export interface GroupMeta {
createdAt: Date;
}

const groupMetaCache = new Map<number, unknown>();

export const groupService = {
async getMetaOfGroup (id: number): Promise<Result<GroupMeta, Diagnostic>> {
const res = await $fetch('/api/groups', {
method: 'get',
query: {
id,
},
});
async getMetaOfGroup(id: number): Promise<Result<GroupMeta, Diagnostic>> {
if (!groupMetaCache.has(id)) {
const res = await $fetch('/api/groups', {
method: 'get',
query: {
id,
},
});
groupMetaCache.set(id, res);
}
const res = groupMetaCache.get(id) as any;
if (res.error) {
return new Err({ code: res.error.code, message: res.error.message });
}
const { ok: { data } } = res;
return new Ok({ name: data.name, id: data.id, createdAt: data.createdAt });

},
};
20 changes: 13 additions & 7 deletions services/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@ export interface UserMeta {
createdAt: Date;
}

const userMetaCache = new Map<number, unknown>();

export const userService = {
async getMetaOfUser(id: number): Promise<Result<UserMeta, Diagnostic>> {
const res = await $fetch('/api/users', {
method: 'get',
query: {
id,
},
credentials: 'include',
});
if (!userMetaCache.has(id)) {
const res = await $fetch('/api/users', {
method: 'get',
query: {
id,
},
credentials: 'include',
});
userMetaCache.set(id, res);
}
const res = userMetaCache.get(id) as any;
if (res.error) {
return new Err({ code: res.error.code, message: res.error.message });
}
Expand Down

0 comments on commit cc293b9

Please sign in to comment.