Mega push vol 5, working on messaging now
This commit is contained in:
@@ -27,19 +27,26 @@ export async function createDocument(
|
||||
supabase: SupabaseClient<Database>,
|
||||
orgId: string,
|
||||
name: string,
|
||||
type: 'folder' | 'document',
|
||||
type: 'folder' | 'document' | 'kanban',
|
||||
parentId: string | null = null,
|
||||
userId: string
|
||||
userId: string,
|
||||
options?: { id?: string; content?: import('$lib/supabase/types').Json }
|
||||
): Promise<Document> {
|
||||
let content: import('$lib/supabase/types').Json | null = options?.content ?? null;
|
||||
if (!content && type === 'document') {
|
||||
content = { type: 'doc', content: [] };
|
||||
}
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from('documents')
|
||||
.insert({
|
||||
...(options?.id ? { id: options.id } : {}),
|
||||
org_id: orgId,
|
||||
name,
|
||||
type,
|
||||
parent_id: parentId,
|
||||
created_by: userId,
|
||||
content: type === 'document' ? { type: 'doc', content: [] } : null
|
||||
content,
|
||||
})
|
||||
.select()
|
||||
.single();
|
||||
@@ -99,6 +106,33 @@ export async function moveDocument(
|
||||
}
|
||||
|
||||
|
||||
export async function copyDocument(
|
||||
supabase: SupabaseClient<Database>,
|
||||
doc: Pick<Document, 'name' | 'type' | 'parent_id' | 'content'>,
|
||||
orgId: string,
|
||||
userId: string
|
||||
): Promise<Document> {
|
||||
const { data, error } = await supabase
|
||||
.from('documents')
|
||||
.insert({
|
||||
org_id: orgId,
|
||||
name: `${doc.name} (copy)`,
|
||||
type: doc.type,
|
||||
parent_id: doc.parent_id,
|
||||
created_by: userId,
|
||||
content: doc.content,
|
||||
})
|
||||
.select()
|
||||
.single();
|
||||
|
||||
if (error) {
|
||||
log.error('copyDocument failed', { error, data: { orgId, name: doc.name } });
|
||||
throw error;
|
||||
}
|
||||
log.info('copyDocument ok', { data: { id: data.id, name: data.name } });
|
||||
return data;
|
||||
}
|
||||
|
||||
export function subscribeToDocuments(
|
||||
supabase: SupabaseClient<Database>,
|
||||
orgId: string,
|
||||
|
||||
Reference in New Issue
Block a user