Files
sign/packages/trpc/server/admin-router/router.ts

45 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-09-29 17:26:37 +01:00
import { TRPCError } from '@trpc/server';
import { updateUser } from '@documenso/lib/server-only/admin/update-user';
2024-02-23 10:47:01 +00:00
import { upsertSiteSetting } from '@documenso/lib/server-only/site-settings/upsert-site-setting';
2023-09-29 17:26:37 +01:00
2023-10-11 12:32:33 +03:00
import { adminProcedure, router } from '../trpc';
2024-02-23 10:47:01 +00:00
import { ZUpdateProfileMutationByAdminSchema, ZUpdateSiteSettingMutationSchema } from './schema';
2023-09-29 17:26:37 +01:00
export const adminRouter = router({
2023-10-11 12:32:33 +03:00
updateUser: adminProcedure
2023-09-29 17:26:37 +01:00
.input(ZUpdateProfileMutationByAdminSchema)
2023-10-11 12:32:33 +03:00
.mutation(async ({ input }) => {
2023-09-29 17:26:37 +01:00
const { id, name, email, roles } = input;
try {
return await updateUser({ id, name, email, roles });
} catch (err) {
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'We were unable to retrieve the specified account. Please try again.',
});
}
}),
2024-02-23 10:47:01 +00:00
updateSiteSetting: adminProcedure
.input(ZUpdateSiteSettingMutationSchema)
.mutation(async ({ ctx, input }) => {
try {
const { id, enabled, data } = input;
return await upsertSiteSetting({
id,
enabled,
data,
userId: ctx.user.id,
});
} catch (err) {
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'We were unable to update the site setting provided.',
});
}
}),
2023-09-29 17:26:37 +01:00
});