Refine documents UX and extract document scope helpers
This commit is contained in:
@@ -600,6 +600,52 @@ async function createCommunication(auth: AuthContext | null, input: {
|
||||
return { ok: true, id: created.id };
|
||||
}
|
||||
|
||||
async function createWorkspaceDocument(auth: AuthContext | null, input: {
|
||||
title: string;
|
||||
type?: string;
|
||||
owner?: string;
|
||||
scope: string;
|
||||
summary: string;
|
||||
body?: string;
|
||||
}) {
|
||||
const ctx = requireAuth(auth);
|
||||
const title = String(input?.title ?? "").trim();
|
||||
const scope = String(input?.scope ?? "").trim();
|
||||
const summary = String(input?.summary ?? "").trim();
|
||||
const body = String(input?.body ?? "").trim();
|
||||
const owner = String(input?.owner ?? "").trim() || "Workspace";
|
||||
const typeRaw = String(input?.type ?? "Template").trim();
|
||||
const allowedTypes = new Set(["Regulation", "Playbook", "Policy", "Template"]);
|
||||
const type = allowedTypes.has(typeRaw) ? typeRaw : "Template";
|
||||
|
||||
if (!title) throw new Error("title is required");
|
||||
if (!scope) throw new Error("scope is required");
|
||||
if (!summary) throw new Error("summary is required");
|
||||
|
||||
const created = await prisma.workspaceDocument.create({
|
||||
data: {
|
||||
teamId: ctx.teamId,
|
||||
title,
|
||||
type: type as any,
|
||||
owner,
|
||||
scope,
|
||||
summary,
|
||||
body: body || summary,
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
id: created.id,
|
||||
title: created.title,
|
||||
type: created.type,
|
||||
owner: created.owner,
|
||||
scope: created.scope,
|
||||
updatedAt: created.updatedAt.toISOString(),
|
||||
summary: created.summary,
|
||||
body: created.body,
|
||||
};
|
||||
}
|
||||
|
||||
async function updateCommunicationTranscript(auth: AuthContext | null, id: string, transcript: string[]) {
|
||||
const ctx = requireAuth(auth);
|
||||
const messageId = String(id ?? "").trim();
|
||||
@@ -951,6 +997,7 @@ export const crmGraphqlSchema = buildSchema(`
|
||||
createCalendarEvent(input: CreateCalendarEventInput!): CalendarEvent!
|
||||
archiveCalendarEvent(input: ArchiveCalendarEventInput!): CalendarEvent!
|
||||
createCommunication(input: CreateCommunicationInput!): MutationWithIdResult!
|
||||
createWorkspaceDocument(input: CreateWorkspaceDocumentInput!): WorkspaceDocument!
|
||||
updateCommunicationTranscript(id: ID!, transcript: [String!]!): MutationWithIdResult!
|
||||
updateFeedDecision(id: ID!, decision: String!, decisionNote: String): MutationWithIdResult!
|
||||
}
|
||||
@@ -996,6 +1043,15 @@ export const crmGraphqlSchema = buildSchema(`
|
||||
transcript: [String!]
|
||||
}
|
||||
|
||||
input CreateWorkspaceDocumentInput {
|
||||
title: String!
|
||||
type: String
|
||||
owner: String
|
||||
scope: String!
|
||||
summary: String!
|
||||
body: String
|
||||
}
|
||||
|
||||
type MePayload {
|
||||
user: MeUser!
|
||||
team: MeTeam!
|
||||
@@ -1232,6 +1288,20 @@ export const crmGraphqlRoot = {
|
||||
context: GraphQLContext,
|
||||
) => createCommunication(context.auth, args.input),
|
||||
|
||||
createWorkspaceDocument: async (
|
||||
args: {
|
||||
input: {
|
||||
title: string;
|
||||
type?: string;
|
||||
owner?: string;
|
||||
scope: string;
|
||||
summary: string;
|
||||
body?: string;
|
||||
};
|
||||
},
|
||||
context: GraphQLContext,
|
||||
) => createWorkspaceDocument(context.auth, args.input),
|
||||
|
||||
updateCommunicationTranscript: async (
|
||||
args: { id: string; transcript: string[] },
|
||||
context: GraphQLContext,
|
||||
|
||||
Reference in New Issue
Block a user