Remove document version from trust API
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
@@ -9,34 +9,31 @@ import {
|
|||||||
DocumentTypeBadge,
|
DocumentTypeBadge,
|
||||||
Button,
|
Button,
|
||||||
IconArrowDown,
|
IconArrowDown,
|
||||||
|
useToast,
|
||||||
} from "@probo/ui";
|
} from "@probo/ui";
|
||||||
import { useTranslate } from "@probo/i18n";
|
import { useTranslate } from "@probo/i18n";
|
||||||
import { graphql } from "relay-runtime";
|
import { buildEndpoint } from "/providers/RelayProviders";
|
||||||
import { useMutation } from "react-relay";
|
// Manual mutation for trust API (not processed by relay compiler)
|
||||||
import type { PublicTrustCenterDocumentsExportPDFMutation } from "./__generated__/PublicTrustCenterDocumentsExportPDFMutation.graphql";
|
const exportDocumentPDFMutation = {
|
||||||
|
params: {
|
||||||
const exportDocumentVersionPDFMutation = graphql`
|
name: "PublicTrustCenterDocumentsExportPDFMutation",
|
||||||
|
operationKind: "mutation",
|
||||||
|
text: `
|
||||||
mutation PublicTrustCenterDocumentsExportPDFMutation(
|
mutation PublicTrustCenterDocumentsExportPDFMutation(
|
||||||
$input: ExportDocumentVersionPDFInput!
|
$input: ExportDocumentPDFInput!
|
||||||
) {
|
) {
|
||||||
exportDocumentVersionPDF(input: $input) {
|
exportDocumentPDF(input: $input) {
|
||||||
data
|
data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
type Document = {
|
type Document = {
|
||||||
id: string;
|
id: string;
|
||||||
title: string;
|
title: string;
|
||||||
documentType: string;
|
documentType: string;
|
||||||
versions: {
|
|
||||||
edges: Array<{
|
|
||||||
node: {
|
|
||||||
id: string;
|
|
||||||
status: string;
|
|
||||||
};
|
|
||||||
}>;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@@ -44,29 +41,56 @@ type Props = {
|
|||||||
isAuthenticated: boolean;
|
isAuthenticated: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type ExportDocumentPDFResponse = {
|
||||||
|
data?: {
|
||||||
|
exportDocumentPDF?: {
|
||||||
|
data: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
errors?: Array<{ message: string }>;
|
||||||
|
};
|
||||||
|
|
||||||
export function PublicTrustCenterDocuments({ documents, isAuthenticated }: Props) {
|
export function PublicTrustCenterDocuments({ documents, isAuthenticated }: Props) {
|
||||||
const { __ } = useTranslate();
|
const { __ } = useTranslate();
|
||||||
const [exportDocumentVersionPDF] = useMutation<PublicTrustCenterDocumentsExportPDFMutation>(exportDocumentVersionPDFMutation);
|
const { toast } = useToast();
|
||||||
|
|
||||||
const handleDownload = (document: Document) => {
|
const handleDownload = async (document: Document) => {
|
||||||
const latestVersion = document.versions.edges[0]?.node;
|
try {
|
||||||
if (!latestVersion) return;
|
const response = await fetch(buildEndpoint("/api/trust/v1/graphql"), {
|
||||||
|
method: "POST",
|
||||||
exportDocumentVersionPDF({
|
headers: {
|
||||||
variables: {
|
"Content-Type": "application/json",
|
||||||
input: { documentVersionId: latestVersion.id },
|
"Accept": "application/json",
|
||||||
},
|
},
|
||||||
onCompleted: (data) => {
|
credentials: "include",
|
||||||
if (data.exportDocumentVersionPDF?.data) {
|
body: JSON.stringify({
|
||||||
|
operationName: exportDocumentPDFMutation.params.name,
|
||||||
|
query: exportDocumentPDFMutation.params.text,
|
||||||
|
variables: { input: { documentId: document.id } },
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
const result: ExportDocumentPDFResponse = await response.json();
|
||||||
|
|
||||||
|
if (result.errors) {
|
||||||
|
throw new Error(result.errors[0].message);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.data?.exportDocumentPDF?.data) {
|
||||||
const link = window.document.createElement("a");
|
const link = window.document.createElement("a");
|
||||||
link.href = data.exportDocumentVersionPDF.data;
|
link.href = result.data.exportDocumentPDF.data;
|
||||||
link.download = `${document.title}.pdf`;
|
link.download = `${document.title}.pdf`;
|
||||||
window.document.body.appendChild(link);
|
window.document.body.appendChild(link);
|
||||||
link.click();
|
link.click();
|
||||||
window.document.body.removeChild(link);
|
window.document.body.removeChild(link);
|
||||||
}
|
}
|
||||||
},
|
} catch (error) {
|
||||||
|
toast({
|
||||||
|
title: __("Download Failed"),
|
||||||
|
description: __("Unable to download the document. Please try again."),
|
||||||
|
variant: "error",
|
||||||
});
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (documents.length === 0) {
|
if (documents.length === 0) {
|
||||||
@@ -105,8 +129,6 @@ export function PublicTrustCenterDocuments({ documents, isAuthenticated }: Props
|
|||||||
</Thead>
|
</Thead>
|
||||||
<Tbody>
|
<Tbody>
|
||||||
{documents.map((document) => {
|
{documents.map((document) => {
|
||||||
const latestVersion = document.versions.edges[0]?.node;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tr key={document.id}>
|
<Tr key={document.id}>
|
||||||
<Td>
|
<Td>
|
||||||
@@ -118,11 +140,7 @@ export function PublicTrustCenterDocuments({ documents, isAuthenticated }: Props
|
|||||||
<DocumentTypeBadge type={document.documentType} />
|
<DocumentTypeBadge type={document.documentType} />
|
||||||
</Td>
|
</Td>
|
||||||
<Td>
|
<Td>
|
||||||
{!latestVersion ? (
|
{!isAuthenticated ? (
|
||||||
<span className="text-txt-tertiary text-sm">
|
|
||||||
{__("No version available")}
|
|
||||||
</span>
|
|
||||||
) : !isAuthenticated ? (
|
|
||||||
<span className="text-txt-tertiary text-sm">
|
<span className="text-txt-tertiary text-sm">
|
||||||
{__("Not available")}
|
{__("Not available")}
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -1,92 +0,0 @@
|
|||||||
/**
|
|
||||||
* @generated SignedSource<<24fd0dcf15c98ad3d20762e4ccc83a1b>>
|
|
||||||
* @lightSyntaxTransform
|
|
||||||
* @nogrep
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* tslint:disable */
|
|
||||||
/* eslint-disable */
|
|
||||||
// @ts-nocheck
|
|
||||||
|
|
||||||
import { ConcreteRequest } from 'relay-runtime';
|
|
||||||
export type ExportDocumentVersionPDFInput = {
|
|
||||||
documentVersionId: string;
|
|
||||||
};
|
|
||||||
export type PublicTrustCenterDocumentsExportPDFMutation$variables = {
|
|
||||||
input: ExportDocumentVersionPDFInput;
|
|
||||||
};
|
|
||||||
export type PublicTrustCenterDocumentsExportPDFMutation$data = {
|
|
||||||
readonly exportDocumentVersionPDF: {
|
|
||||||
readonly data: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
export type PublicTrustCenterDocumentsExportPDFMutation = {
|
|
||||||
response: PublicTrustCenterDocumentsExportPDFMutation$data;
|
|
||||||
variables: PublicTrustCenterDocumentsExportPDFMutation$variables;
|
|
||||||
};
|
|
||||||
|
|
||||||
const node: ConcreteRequest = (function(){
|
|
||||||
var v0 = [
|
|
||||||
{
|
|
||||||
"defaultValue": null,
|
|
||||||
"kind": "LocalArgument",
|
|
||||||
"name": "input"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
v1 = [
|
|
||||||
{
|
|
||||||
"alias": null,
|
|
||||||
"args": [
|
|
||||||
{
|
|
||||||
"kind": "Variable",
|
|
||||||
"name": "input",
|
|
||||||
"variableName": "input"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"concreteType": "ExportDocumentVersionPDFPayload",
|
|
||||||
"kind": "LinkedField",
|
|
||||||
"name": "exportDocumentVersionPDF",
|
|
||||||
"plural": false,
|
|
||||||
"selections": [
|
|
||||||
{
|
|
||||||
"alias": null,
|
|
||||||
"args": null,
|
|
||||||
"kind": "ScalarField",
|
|
||||||
"name": "data",
|
|
||||||
"storageKey": null
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"storageKey": null
|
|
||||||
}
|
|
||||||
];
|
|
||||||
return {
|
|
||||||
"fragment": {
|
|
||||||
"argumentDefinitions": (v0/*: any*/),
|
|
||||||
"kind": "Fragment",
|
|
||||||
"metadata": null,
|
|
||||||
"name": "PublicTrustCenterDocumentsExportPDFMutation",
|
|
||||||
"selections": (v1/*: any*/),
|
|
||||||
"type": "Mutation",
|
|
||||||
"abstractKey": null
|
|
||||||
},
|
|
||||||
"kind": "Request",
|
|
||||||
"operation": {
|
|
||||||
"argumentDefinitions": (v0/*: any*/),
|
|
||||||
"kind": "Operation",
|
|
||||||
"name": "PublicTrustCenterDocumentsExportPDFMutation",
|
|
||||||
"selections": (v1/*: any*/)
|
|
||||||
},
|
|
||||||
"params": {
|
|
||||||
"cacheID": "b5d33d4c301cfa811bb74d52f61f52e8",
|
|
||||||
"id": null,
|
|
||||||
"metadata": {},
|
|
||||||
"name": "PublicTrustCenterDocumentsExportPDFMutation",
|
|
||||||
"operationKind": "mutation",
|
|
||||||
"text": "mutation PublicTrustCenterDocumentsExportPDFMutation(\n $input: ExportDocumentVersionPDFInput!\n) {\n exportDocumentVersionPDF(input: $input) {\n data\n }\n}\n"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
})();
|
|
||||||
|
|
||||||
(node as any).hash = "b6a173895aea2450ad4ac1a4ec6aeb4e";
|
|
||||||
|
|
||||||
export default node;
|
|
||||||
@@ -20,13 +20,6 @@ export const publicTrustCenterQuery = {
|
|||||||
id
|
id
|
||||||
title
|
title
|
||||||
documentType
|
documentType
|
||||||
versions(first: 1) {
|
|
||||||
edges {
|
|
||||||
node {
|
|
||||||
id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -321,6 +321,59 @@ LIMIT 1;
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *DocumentVersion) LoadLatestPublishedVersion(
|
||||||
|
ctx context.Context,
|
||||||
|
conn pg.Conn,
|
||||||
|
scope Scoper,
|
||||||
|
documentID gid.GID,
|
||||||
|
) error {
|
||||||
|
q := `
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
document_id,
|
||||||
|
title,
|
||||||
|
owner_id,
|
||||||
|
version_number,
|
||||||
|
content,
|
||||||
|
changelog,
|
||||||
|
created_by,
|
||||||
|
status,
|
||||||
|
published_by,
|
||||||
|
published_at,
|
||||||
|
created_at,
|
||||||
|
updated_at
|
||||||
|
FROM
|
||||||
|
document_versions
|
||||||
|
WHERE
|
||||||
|
%s
|
||||||
|
AND document_id = @document_id
|
||||||
|
AND status = @status
|
||||||
|
ORDER BY published_at DESC
|
||||||
|
LIMIT 1;
|
||||||
|
`
|
||||||
|
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||||
|
|
||||||
|
args := pgx.StrictNamedArgs{
|
||||||
|
"document_id": documentID,
|
||||||
|
"status": DocumentStatusPublished,
|
||||||
|
}
|
||||||
|
maps.Copy(args, scope.SQLArguments())
|
||||||
|
|
||||||
|
rows, err := conn.Query(ctx, q, args)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cannot query document versions: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
documentVersion, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[DocumentVersion])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cannot collect document version: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
*p = documentVersion
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (p DocumentVersion) Update(
|
func (p DocumentVersion) Update(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
conn pg.Conn,
|
conn pg.Conn,
|
||||||
|
|||||||
@@ -48,20 +48,10 @@ enum DocumentType
|
|||||||
@goEnum(value: "github.com/getprobo/probo/pkg/coredata.DocumentTypePolicy")
|
@goEnum(value: "github.com/getprobo/probo/pkg/coredata.DocumentTypePolicy")
|
||||||
}
|
}
|
||||||
|
|
||||||
type DocumentVersion implements Node {
|
|
||||||
id: ID!
|
|
||||||
}
|
|
||||||
|
|
||||||
type Document implements Node {
|
type Document implements Node {
|
||||||
id: ID!
|
id: ID!
|
||||||
title: String!
|
title: String!
|
||||||
documentType: DocumentType!
|
documentType: DocumentType!
|
||||||
versions(
|
|
||||||
first: Int
|
|
||||||
after: CursorKey
|
|
||||||
last: Int
|
|
||||||
before: CursorKey
|
|
||||||
): DocumentVersionConnection! @goField(forceResolver: true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type DocumentConnection {
|
type DocumentConnection {
|
||||||
@@ -74,16 +64,6 @@ type DocumentEdge {
|
|||||||
node: Document!
|
node: Document!
|
||||||
}
|
}
|
||||||
|
|
||||||
type DocumentVersionConnection {
|
|
||||||
edges: [DocumentVersionEdge!]!
|
|
||||||
pageInfo: PageInfo!
|
|
||||||
}
|
|
||||||
|
|
||||||
type DocumentVersionEdge {
|
|
||||||
cursor: CursorKey!
|
|
||||||
node: DocumentVersion!
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
type Framework implements Node {
|
type Framework implements Node {
|
||||||
id: ID!
|
id: ID!
|
||||||
@@ -244,11 +224,11 @@ type TrustCenter implements Node {
|
|||||||
): VendorConnection! @goField(forceResolver: true)
|
): VendorConnection! @goField(forceResolver: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
input ExportDocumentVersionPDFInput {
|
input ExportDocumentPDFInput {
|
||||||
documentVersionId: ID!
|
documentId: ID!
|
||||||
}
|
}
|
||||||
|
|
||||||
type ExportDocumentVersionPDFPayload {
|
type ExportDocumentPDFPayload {
|
||||||
data: String!
|
data: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,7 +237,7 @@ type Query {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Mutation {
|
type Mutation {
|
||||||
exportDocumentVersionPDF(
|
exportDocumentPDF(
|
||||||
input: ExportDocumentVersionPDFInput!
|
input: ExportDocumentPDFInput!
|
||||||
): ExportDocumentVersionPDFPayload! @mustBeAuthenticated(role: USER)
|
): ExportDocumentPDFPayload! @mustBeAuthenticated(role: USER)
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,47 +0,0 @@
|
|||||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
|
||||||
//
|
|
||||||
// Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
// purpose with or without fee is hereby granted, provided that the above
|
|
||||||
// copyright notice and this permission notice appear in all copies.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
||||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
||||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
||||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
||||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
||||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
||||||
// PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
|
|
||||||
package types
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/getprobo/probo/pkg/coredata"
|
|
||||||
"github.com/getprobo/probo/pkg/page"
|
|
||||||
)
|
|
||||||
|
|
||||||
func NewDocumentVersionConnection(
|
|
||||||
p *page.Page[*coredata.DocumentVersion, coredata.DocumentVersionOrderField],
|
|
||||||
) *DocumentVersionConnection {
|
|
||||||
edges := make([]*DocumentVersionEdge, len(p.Data))
|
|
||||||
for i, documentVersion := range p.Data {
|
|
||||||
edges[i] = NewDocumentVersionEdge(documentVersion, p.Cursor.OrderBy.Field)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &DocumentVersionConnection{
|
|
||||||
Edges: edges,
|
|
||||||
PageInfo: NewPageInfo(p),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewDocumentVersion(dv *coredata.DocumentVersion) *DocumentVersion {
|
|
||||||
return &DocumentVersion{
|
|
||||||
ID: dv.ID,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewDocumentVersionEdge(dv *coredata.DocumentVersion, orderField coredata.DocumentVersionOrderField) *DocumentVersionEdge {
|
|
||||||
return &DocumentVersionEdge{
|
|
||||||
Node: NewDocumentVersion(dv),
|
|
||||||
Cursor: dv.CursorKey(orderField),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -42,7 +42,6 @@ type Document struct {
|
|||||||
ID gid.GID `json:"id"`
|
ID gid.GID `json:"id"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
DocumentType coredata.DocumentType `json:"documentType"`
|
DocumentType coredata.DocumentType `json:"documentType"`
|
||||||
Versions *DocumentVersionConnection `json:"versions"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Document) IsNode() {}
|
func (Document) IsNode() {}
|
||||||
@@ -58,28 +57,11 @@ type DocumentEdge struct {
|
|||||||
Node *Document `json:"node"`
|
Node *Document `json:"node"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DocumentVersion struct {
|
type ExportDocumentPDFInput struct {
|
||||||
ID gid.GID `json:"id"`
|
DocumentID gid.GID `json:"documentId"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (DocumentVersion) IsNode() {}
|
type ExportDocumentPDFPayload struct {
|
||||||
func (this DocumentVersion) GetID() gid.GID { return this.ID }
|
|
||||||
|
|
||||||
type DocumentVersionConnection struct {
|
|
||||||
Edges []*DocumentVersionEdge `json:"edges"`
|
|
||||||
PageInfo *PageInfo `json:"pageInfo"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type DocumentVersionEdge struct {
|
|
||||||
Cursor page.CursorKey `json:"cursor"`
|
|
||||||
Node *DocumentVersion `json:"node"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ExportDocumentVersionPDFInput struct {
|
|
||||||
DocumentVersionID gid.GID `json:"documentVersionId"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ExportDocumentVersionPDFPayload struct {
|
|
||||||
Data string `json:"data"`
|
Data string `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,50 +76,16 @@ func (r *auditResolver) ReportURL(ctx context.Context, obj *types.Audit) (*strin
|
|||||||
return url, nil
|
return url, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Versions is the resolver for the versions field.
|
// ExportDocumentPDF is the resolver for the exportDocumentPDF field.
|
||||||
func (r *documentResolver) Versions(ctx context.Context, obj *types.Document, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.DocumentVersionConnection, error) {
|
func (r *mutationResolver) ExportDocumentPDF(ctx context.Context, input types.ExportDocumentPDFInput) (*types.ExportDocumentPDFPayload, error) {
|
||||||
trust := r.TrustService(ctx, obj.ID.TenantID())
|
trust := r.trustCenterSvc.WithTenant(input.DocumentID.TenantID())
|
||||||
|
|
||||||
pageOrderBy := page.OrderBy[coredata.DocumentVersionOrderField]{
|
pdf, err := trust.Documents.ExportPDF(ctx, input.DocumentID)
|
||||||
Field: coredata.DocumentVersionOrderFieldCreatedAt,
|
|
||||||
Direction: page.OrderDirectionDesc,
|
|
||||||
}
|
|
||||||
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
|
||||||
|
|
||||||
// For the public trust API, only return published versions
|
|
||||||
page, err := trust.Documents.ListVersions(ctx, obj.ID, cursor)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cannot list document versions: %w", err)
|
return nil, fmt.Errorf("cannot export document PDF: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter to only published versions and create edges directly
|
return &types.ExportDocumentPDFPayload{
|
||||||
publishedEdges := make([]*types.DocumentVersionEdge, 0)
|
|
||||||
for _, version := range page.Data {
|
|
||||||
if version.Status == coredata.DocumentStatusPublished {
|
|
||||||
edge := &types.DocumentVersionEdge{
|
|
||||||
Cursor: version.CursorKey(pageOrderBy.Field),
|
|
||||||
Node: types.NewDocumentVersion(version),
|
|
||||||
}
|
|
||||||
publishedEdges = append(publishedEdges, edge)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return &types.DocumentVersionConnection{
|
|
||||||
Edges: publishedEdges,
|
|
||||||
PageInfo: types.NewPageInfo(page),
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExportDocumentVersionPDF is the resolver for the exportDocumentVersionPDF field.
|
|
||||||
func (r *mutationResolver) ExportDocumentVersionPDF(ctx context.Context, input types.ExportDocumentVersionPDFInput) (*types.ExportDocumentVersionPDFPayload, error) {
|
|
||||||
trust := r.trustCenterSvc.WithTenant(input.DocumentVersionID.TenantID())
|
|
||||||
|
|
||||||
pdf, err := trust.Documents.ExportPDF(ctx, input.DocumentVersionID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("cannot export document version PDF: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &types.ExportDocumentVersionPDFPayload{
|
|
||||||
Data: fmt.Sprintf("data:application/pdf;base64,%s", base64.StdEncoding.EncodeToString(pdf)),
|
Data: fmt.Sprintf("data:application/pdf;base64,%s", base64.StdEncoding.EncodeToString(pdf)),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@@ -231,9 +197,6 @@ func (r *trustCenterResolver) Vendors(ctx context.Context, obj *types.TrustCente
|
|||||||
// Audit returns schema.AuditResolver implementation.
|
// Audit returns schema.AuditResolver implementation.
|
||||||
func (r *Resolver) Audit() schema.AuditResolver { return &auditResolver{r} }
|
func (r *Resolver) Audit() schema.AuditResolver { return &auditResolver{r} }
|
||||||
|
|
||||||
// Document returns schema.DocumentResolver implementation.
|
|
||||||
func (r *Resolver) Document() schema.DocumentResolver { return &documentResolver{r} }
|
|
||||||
|
|
||||||
// Mutation returns schema.MutationResolver implementation.
|
// Mutation returns schema.MutationResolver implementation.
|
||||||
func (r *Resolver) Mutation() schema.MutationResolver { return &mutationResolver{r} }
|
func (r *Resolver) Mutation() schema.MutationResolver { return &mutationResolver{r} }
|
||||||
|
|
||||||
@@ -250,7 +213,6 @@ func (r *Resolver) Report() schema.ReportResolver { return &reportResolver{r} }
|
|||||||
func (r *Resolver) TrustCenter() schema.TrustCenterResolver { return &trustCenterResolver{r} }
|
func (r *Resolver) TrustCenter() schema.TrustCenterResolver { return &trustCenterResolver{r} }
|
||||||
|
|
||||||
type auditResolver struct{ *Resolver }
|
type auditResolver struct{ *Resolver }
|
||||||
type documentResolver struct{ *Resolver }
|
|
||||||
type mutationResolver struct{ *Resolver }
|
type mutationResolver struct{ *Resolver }
|
||||||
type organizationResolver struct{ *Resolver }
|
type organizationResolver struct{ *Resolver }
|
||||||
type queryResolver struct{ *Resolver }
|
type queryResolver struct{ *Resolver }
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ func (s *DocumentService) ListForOrganizationId(
|
|||||||
|
|
||||||
func (s *DocumentService) ExportPDF(
|
func (s *DocumentService) ExportPDF(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
documentVersionID gid.GID,
|
documentID gid.GID,
|
||||||
) ([]byte, error) {
|
) ([]byte, error) {
|
||||||
document := &coredata.Document{}
|
document := &coredata.Document{}
|
||||||
version := &coredata.DocumentVersion{}
|
version := &coredata.DocumentVersion{}
|
||||||
@@ -97,11 +97,7 @@ func (s *DocumentService) ExportPDF(
|
|||||||
err := s.svc.pg.WithConn(
|
err := s.svc.pg.WithConn(
|
||||||
ctx,
|
ctx,
|
||||||
func(conn pg.Conn) error {
|
func(conn pg.Conn) error {
|
||||||
if err := version.LoadByID(ctx, conn, s.svc.scope, documentVersionID); err != nil {
|
if err := document.LoadByID(ctx, conn, s.svc.scope, documentID); err != nil {
|
||||||
return fmt.Errorf("cannot load document version: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := document.LoadByID(ctx, conn, s.svc.scope, version.DocumentID); err != nil {
|
|
||||||
return fmt.Errorf("cannot load document: %w", err)
|
return fmt.Errorf("cannot load document: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,6 +105,10 @@ func (s *DocumentService) ExportPDF(
|
|||||||
return fmt.Errorf("document not visible on trust center")
|
return fmt.Errorf("document not visible on trust center")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := version.LoadLatestPublishedVersion(ctx, conn, s.svc.scope, documentID); err != nil {
|
||||||
|
return fmt.Errorf("cannot load latest published document version: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
if version.PublishedBy != nil {
|
if version.PublishedBy != nil {
|
||||||
if err := publishedBy.LoadByID(ctx, conn, s.svc.scope, *version.PublishedBy); err != nil {
|
if err := publishedBy.LoadByID(ctx, conn, s.svc.scope, *version.PublishedBy); err != nil {
|
||||||
return fmt.Errorf("cannot load published by person: %w", err)
|
return fmt.Errorf("cannot load published by person: %w", err)
|
||||||
@@ -125,7 +125,7 @@ func (s *DocumentService) ExportPDF(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
if err := signatures.LoadByDocumentVersionID(ctx, conn, s.svc.scope, documentVersionID, cursor); err != nil {
|
if err := signatures.LoadByDocumentVersionID(ctx, conn, s.svc.scope, version.ID, cursor); err != nil {
|
||||||
return fmt.Errorf("cannot load document version signatures: %w", err)
|
return fmt.Errorf("cannot load document version signatures: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user