37 lines
818 B
TypeScript
37 lines
818 B
TypeScript
import { user } from "../user";
|
|
|
|
export const loadUserConf = async (user_id: string) => {
|
|
const conf = user.conf.getOrCreate(user_id);
|
|
if (conf) {
|
|
if (!conf.site_id) {
|
|
const site = await db.site.findFirst({
|
|
where: {
|
|
id_user: user_id,
|
|
is_deleted: false,
|
|
},
|
|
select: { id: true },
|
|
});
|
|
if (site) {
|
|
conf.site_id = site.id;
|
|
user.conf.set(user_id, "site_id", site.id);
|
|
}
|
|
}
|
|
|
|
if (conf.site_id && !conf.page_id) {
|
|
const page = await db.page.findFirst({
|
|
select: { id: true },
|
|
where: {
|
|
id_site: conf.site_id,
|
|
is_deleted: false,
|
|
},
|
|
});
|
|
|
|
if (page) {
|
|
conf.page_id = page.id;
|
|
user.conf.set(user_id, "page_id", page.id);
|
|
}
|
|
}
|
|
}
|
|
return conf;
|
|
};
|