add user config routes
This commit is contained in:
30
src/userConfig/userConfig.service.ts
Normal file
30
src/userConfig/userConfig.service.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { AuthenticatedUser } from "../auth";
|
||||
import { UpdateUserConfigInput, userConfigModel } from "./userConfig.schema";
|
||||
|
||||
export async function createUserConfig(userId: string, tenantId: string) {
|
||||
await userConfigModel.create({ tenantId, userId, config: {} });
|
||||
}
|
||||
|
||||
export async function getConfig(user: AuthenticatedUser) {
|
||||
return await userConfigModel.findOne({
|
||||
tenantId: user.tenantId,
|
||||
userId: user.userId,
|
||||
});
|
||||
}
|
||||
|
||||
export async function updateConfig(
|
||||
input: UpdateUserConfigInput,
|
||||
user: AuthenticatedUser
|
||||
) {
|
||||
return await userConfigModel.findOneAndUpdate(
|
||||
{ tenantId: user.tenantId, userId: user.userId },
|
||||
{
|
||||
...input,
|
||||
},
|
||||
{ new: true }
|
||||
);
|
||||
}
|
||||
|
||||
export async function deleteConfig(userId: string, tenantId: string) {
|
||||
await userConfigModel.deleteOne({ userId: userId, tenantId: tenantId });
|
||||
}
|
||||
Reference in New Issue
Block a user