B2B-30: adds personal code to account, company admins invites members

This commit is contained in:
devmc-ee
2025-06-22 15:22:07 +03:00
parent 39c02c6d34
commit 251f2a4ef1
50 changed files with 3546 additions and 2611 deletions

View File

@@ -160,7 +160,7 @@ export const deleteAccountAction = adminAction(
*/
export const createUserAction = adminAction(
enhanceAction(
async ({ email, password, emailConfirm }) => {
async ({ email, password, emailConfirm, personalCode }) => {
const adminClient = getSupabaseServerAdminClient();
const logger = await getLogger();
@@ -182,6 +182,16 @@ export const createUserAction = adminAction(
`Super Admin has successfully created a new user`,
);
const { error: accountError } = await adminClient
.from('accounts')
.update({ personal_code: personalCode })
.eq('id', data.user.id);
if (accountError) {
logger.error({ accountError }, 'Error inserting personal code to accounts');
throw new Error(`Error saving personal code: ${accountError.message}`);
}
revalidateAdmin();
return {

View File

@@ -0,0 +1,10 @@
import { z } from 'zod';
export const CreateUserProfileSchema = z.object({
personalCode: z.string().regex(/^[1-6]\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}\d$/, {
message: 'Invalid Estonian personal code format',
}),
});
export type CreateUserProfileSchemaType = z.infer<typeof CreateUserProfileSchema>;

View File

@@ -1,6 +1,9 @@
import { z } from 'zod';
export const CreateUserSchema = z.object({
personalCode: z.string().regex(/^[1-6]\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}\d$/, {
message: 'Invalid Estonian personal code format',
}),
email: z.string().email({ message: 'Please enter a valid email address' }),
password: z
.string()