Implement company provisioning codes and session tweaks
This commit is contained in:
parent
0fb9bf59b2
commit
2cba553efa
28 changed files with 1407 additions and 534 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import { randomBytes } from "@noble/hashes/utils"
|
||||
import type { Id } from "./_generated/dataModel"
|
||||
import { mutation } from "./_generated/server"
|
||||
|
||||
|
|
@ -86,6 +87,7 @@ export const seedDemo = mutation({
|
|||
phone?: string;
|
||||
description?: string;
|
||||
address?: string;
|
||||
provisioningCode?: string;
|
||||
}): Promise<Id<"companies">> {
|
||||
const slug = def.slug ?? slugify(def.name);
|
||||
const existing = await ctx.db
|
||||
|
|
@ -97,6 +99,7 @@ export const seedDemo = mutation({
|
|||
tenantId,
|
||||
name: def.name,
|
||||
slug,
|
||||
provisioningCode: def.provisioningCode ?? existing?.provisioningCode ?? generateCode(),
|
||||
cnpj: def.cnpj ?? undefined,
|
||||
domain: def.domain ?? undefined,
|
||||
phone: def.phone ?? undefined,
|
||||
|
|
@ -113,6 +116,7 @@ export const seedDemo = mutation({
|
|||
if (existing.phone !== payload.phone) updates.phone = payload.phone;
|
||||
if (existing.description !== payload.description) updates.description = payload.description;
|
||||
if (existing.address !== payload.address) updates.address = payload.address;
|
||||
if (existing.provisioningCode !== payload.provisioningCode) updates.provisioningCode = payload.provisioningCode;
|
||||
if (Object.keys(updates).length > 0) {
|
||||
updates.updatedAt = now;
|
||||
await ctx.db.patch(existing._id, updates);
|
||||
|
|
@ -157,7 +161,16 @@ export const seedDemo = mutation({
|
|||
});
|
||||
}
|
||||
|
||||
const companiesSeed = [
|
||||
const companiesSeed: Array<{
|
||||
name: string;
|
||||
slug: string;
|
||||
cnpj?: string;
|
||||
domain?: string;
|
||||
phone?: string;
|
||||
description?: string;
|
||||
address?: string;
|
||||
provisioningCode?: string;
|
||||
}> = [
|
||||
{
|
||||
name: "Atlas Engenharia Digital",
|
||||
slug: "atlas-engenharia",
|
||||
|
|
@ -387,3 +400,4 @@ export const seedDemo = mutation({
|
|||
});
|
||||
},
|
||||
});
|
||||
const generateCode = () => Array.from(randomBytes(32), (b) => b.toString(16).padStart(2, "0")).join("")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue