fix(capital): address PR #154 review — proper interface instead of as-cast, IInput['data'] canon
document-domain.service.ts: replaced the inline `as Cooperative.Document.IGenerate & {...}`
hack with a dedicated GenerateDocumentWithPrivateDataDomainInterface for the doc_data
pre-generation branch (Cooperative.Document.IGenerate already carries a `[key: string]: any`
index signature, so the narrow interface is assignable without any cast at all).
Onboarding api/index.ts: saveProgramDocDataHash now takes
Mutations.Capital.SaveCapitalProgramDocDataHash.IInput['data'] and forwards it as-is to
variables.data, matching the SDK IInput['data'] canon used by completeStep right above it
instead of taking a bare string and rebuilding the payload inline. Updated both call sites.
This commit is contained in:
+13
@@ -0,0 +1,13 @@
|
||||
import type { Cooperative } from 'cooptypes';
|
||||
|
||||
/**
|
||||
* Узкая задача пред-генерации: документ, у которого часть полей приватна и
|
||||
* хранится off-chain (`doc_data`) — `DocumentDomainService.generateDocument`
|
||||
* сохраняет `doc_data` через `saveDocData` и публикует дальше только
|
||||
* `doc_data_hash`. См. `Cooperative.Document.IDocDataRef` в cooptypes —
|
||||
* on-chain-сторона того же контракта.
|
||||
*/
|
||||
export interface GenerateDocumentWithPrivateDataDomainInterface extends Cooperative.Document.IGenerate {
|
||||
doc_data?: Record<string, unknown>;
|
||||
doc_data_hash?: string;
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import { DocumentPackageAggregator } from '../aggregators/document-package.aggre
|
||||
import { getActions } from '~/utils/getFetch';
|
||||
import { toDotNotation } from '~/utils/toDotNotation';
|
||||
import type { ISignedDocumentDomainInterface } from '../interfaces/signed-document-domain.interface';
|
||||
import type { GenerateDocumentWithPrivateDataDomainInterface } from '../interfaces/generate-document-with-private-data.interface';
|
||||
|
||||
@Injectable()
|
||||
export class DocumentDomainService {
|
||||
@@ -22,10 +23,7 @@ export class DocumentDomainService {
|
||||
) {}
|
||||
|
||||
public async generateDocument(data: GenerateDocumentDomainInterfaceWithOptions): Promise<DocumentDomainEntity> {
|
||||
const documentData = data.data as Cooperative.Document.IGenerate & {
|
||||
doc_data?: Record<string, unknown>;
|
||||
doc_data_hash?: string;
|
||||
};
|
||||
const documentData: GenerateDocumentWithPrivateDataDomainInterface = data.data;
|
||||
|
||||
if (documentData.doc_data) {
|
||||
const { doc_data, ...publicDocumentData } = documentData;
|
||||
@@ -38,7 +36,7 @@ export class DocumentDomainService {
|
||||
data: {
|
||||
...publicDocumentData,
|
||||
doc_data_hash: hash,
|
||||
} as Cooperative.Document.IGenerate,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -22,11 +22,13 @@ const completeStep = async (
|
||||
return state;
|
||||
};
|
||||
|
||||
const saveProgramDocDataHash = async (doc_data_hash: string) => {
|
||||
const saveProgramDocDataHash = async (
|
||||
data: Mutations.Capital.SaveCapitalProgramDocDataHash.IInput['data'],
|
||||
) => {
|
||||
const { [Mutations.Capital.SaveCapitalProgramDocDataHash.name]: state } = await client.Mutation(
|
||||
Mutations.Capital.SaveCapitalProgramDocDataHash.mutation,
|
||||
{
|
||||
variables: { data: { doc_data_hash } },
|
||||
variables: { data },
|
||||
},
|
||||
);
|
||||
return state;
|
||||
|
||||
+1
-1
@@ -168,7 +168,7 @@ export function useCapitalProgramDocParams(options?: { onSaved?: (hash: string)
|
||||
throw new Error('Не удалось получить хеш параметров документов');
|
||||
}
|
||||
|
||||
await api.saveProgramDocDataHash(hash);
|
||||
await api.saveProgramDocDataHash({ doc_data_hash: hash });
|
||||
|
||||
savedHash.value = hash;
|
||||
persistDraftToStorage();
|
||||
|
||||
+1
-1
@@ -224,7 +224,7 @@ async function saveParams() {
|
||||
throw new Error('Не удалось получить хеш параметров документов');
|
||||
}
|
||||
|
||||
await api.saveProgramDocDataHash(hash);
|
||||
await api.saveProgramDocDataHash({ doc_data_hash: hash });
|
||||
|
||||
savedHash.value = hash;
|
||||
emit('saved', hash);
|
||||
|
||||
Reference in New Issue
Block a user