41 lines
791 B
TypeScript
41 lines
791 B
TypeScript
export const useUserStore = defineStore('user', {
|
|
state: () => ({
|
|
users: {} as Record<string, User>
|
|
}),
|
|
getters: {
|
|
get: (state) =>
|
|
{
|
|
return (id: string): User | undefined =>
|
|
{
|
|
return state.users[id];
|
|
}
|
|
}
|
|
},
|
|
actions: {
|
|
add(users: Record<string, User>)
|
|
{
|
|
for (const [id, user] of Object.entries(users))
|
|
{
|
|
if (this.users[id] == null)
|
|
{
|
|
this.users[id] = user;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
|
|
export class EnhancedResponse<P>
|
|
{
|
|
constructor(
|
|
public data: P,
|
|
public users: Record<string, User>
|
|
)
|
|
{
|
|
}
|
|
}
|
|
|
|
export class User
|
|
{
|
|
displayName?: string;
|
|
} |