feat: refactor account
This commit is contained in:
@@ -1,29 +1,12 @@
|
||||
import { EmailSchema, NameSchema } from "@spec/shared";
|
||||
import { event } from "@valkyr/event-store";
|
||||
import { email, name, phone } from "relay/schemas";
|
||||
import z from "zod";
|
||||
|
||||
import { auditor } from "./auditor.ts";
|
||||
|
||||
const created = z.discriminatedUnion([
|
||||
z.object({
|
||||
type: z.literal("admin"),
|
||||
}),
|
||||
z.object({
|
||||
type: z.literal("consultant"),
|
||||
}),
|
||||
z.object({
|
||||
type: z.literal("organization"),
|
||||
organizationId: z.string(),
|
||||
}),
|
||||
]);
|
||||
|
||||
export default [
|
||||
event.type("account:created").data(created).meta(auditor),
|
||||
event.type("account:avatar:added").data(z.string()).meta(auditor),
|
||||
event.type("account:name:added").data(name).meta(auditor),
|
||||
event.type("account:email:added").data(email).meta(auditor),
|
||||
event.type("account:phone:added").data(phone).meta(auditor),
|
||||
event.type("account:name:added").data(NameSchema).meta(auditor),
|
||||
event.type("account:email:added").data(EmailSchema).meta(auditor),
|
||||
event.type("account:role:added").data(z.string()).meta(auditor),
|
||||
];
|
||||
|
||||
export type AccountCreatedData = z.infer<typeof created>;
|
||||
|
||||
@@ -3,7 +3,7 @@ import z from "zod";
|
||||
|
||||
import { auditor } from "./auditor.ts";
|
||||
|
||||
const created = z.object({
|
||||
const CreatedSchema = z.object({
|
||||
name: z.string(),
|
||||
permissions: z.array(
|
||||
z.object({
|
||||
@@ -13,7 +13,7 @@ const created = z.object({
|
||||
),
|
||||
});
|
||||
|
||||
const operation = z.discriminatedUnion([
|
||||
const OperationSchema = z.discriminatedUnion("type", [
|
||||
z.object({
|
||||
type: z.literal("grant"),
|
||||
resource: z.string(),
|
||||
@@ -27,11 +27,11 @@ const operation = z.discriminatedUnion([
|
||||
]);
|
||||
|
||||
export default [
|
||||
event.type("role:created").data(created).meta(auditor),
|
||||
event.type("role:created").data(CreatedSchema).meta(auditor),
|
||||
event.type("role:name-set").data(z.string()).meta(auditor),
|
||||
event.type("role:permissions-set").data(z.array(operation)).meta(auditor),
|
||||
event.type("role:permissions-set").data(z.array(OperationSchema)).meta(auditor),
|
||||
];
|
||||
|
||||
export type RoleCreatedData = z.infer<typeof created>;
|
||||
export type RoleCreatedData = z.infer<typeof CreatedSchema>;
|
||||
|
||||
export type RolePermissionOperation = z.infer<typeof operation>;
|
||||
export type RolePermissionOperation = z.infer<typeof OperationSchema>;
|
||||
|
||||
Reference in New Issue
Block a user