feat: support office document nodes
This commit is contained in:
@@ -127,6 +127,49 @@ func (r *NodeRepository) CreateFile(ctx context.Context, n *model.Node) (*model.
|
||||
`, n.ParentID, n.Title, n.OwnerUserID, n.StorageKey, n.OriginalFilename, n.MimeType, n.Extension, n.SizeBytes).Scan)
|
||||
}
|
||||
|
||||
func (r *NodeRepository) CreateOfficeDocument(ctx context.Context, n *model.Node) (*model.Node, error) {
|
||||
return scanNode(r.pool.QueryRow(ctx, `
|
||||
INSERT INTO files_nodes
|
||||
(parent_id, node_type, title, owner_user_id, created_by, original_filename,
|
||||
mime_type, extension, size_bytes, office_format, external_url)
|
||||
VALUES ($1, 'office_document', $2, $3, $3, $4, $5, $6, $7, $8, $9)
|
||||
RETURNING id, parent_id, node_type, title, owner_user_id, owner_department_id,
|
||||
created_by, updated_by, storage_key, original_filename, mime_type,
|
||||
extension, size_bytes, office_format, external_url, version,
|
||||
'edit' AS effective_access, created_at, updated_at, trashed_at, purge_after, deleted_at
|
||||
`, n.ParentID, n.Title, n.OwnerUserID, n.OriginalFilename, n.MimeType, n.Extension, n.SizeBytes, n.OfficeFormat, n.ExternalURL).Scan)
|
||||
}
|
||||
|
||||
func (r *NodeRepository) ListOfficeExternalURLs(ctx context.Context, userID string, subordinateIDs []string) ([]string, error) {
|
||||
rows, err := r.pool.Query(ctx, `
|
||||
SELECT DISTINCT n.external_url
|
||||
FROM files_nodes n
|
||||
WHERE n.deleted_at IS NULL
|
||||
AND n.node_type = 'office_document'
|
||||
AND n.external_url IS NOT NULL
|
||||
AND (
|
||||
n.owner_user_id = $1
|
||||
OR has_node_access(n.id, $1)
|
||||
OR n.owner_user_id::text = ANY($2::text[])
|
||||
)
|
||||
ORDER BY n.external_url
|
||||
`, userID, subordinateIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
out := make([]string, 0)
|
||||
for rows.Next() {
|
||||
var url string
|
||||
if err := rows.Scan(&url); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, url)
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
func (r *NodeRepository) Update(ctx context.Context, id, actorID string, req model.UpdateNodeRequest) (*model.Node, error) {
|
||||
return scanNode(r.pool.QueryRow(ctx, `
|
||||
UPDATE files_nodes
|
||||
|
||||
Reference in New Issue
Block a user