@vulog/aima-document
Version:
User document management — upload, review, and status tracking.
75 lines (74 loc) • 3.32 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
let zod = require("zod");
//#region src/createOrUpdateDocument.ts
const schema$3 = zod.z.object({ userId: zod.z.string().nonempty().guid() });
const createOrUpdateDocument = async (client, userId, document) => {
const result = schema$3.safeParse({ userId });
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
return client.post(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/documents`, document).then(({ data }) => data);
};
//#endregion
//#region src/types.ts
const personalInformationDocumentTypes = ["DOCUMENT_NUMBER_1"];
const personalInformationDocumentTypeSchema = zod.z.enum(personalInformationDocumentTypes);
//#endregion
//#region src/getUserDocuments.ts
const schema$2 = zod.z.object({
userId: zod.z.string().trim().nonempty().guid(),
types: zod.z.array(personalInformationDocumentTypeSchema).min(0).optional()
});
const getUserDocuments = async (client, userId, types) => {
const result = schema$2.safeParse({
userId,
types
});
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
const docSumary = await client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/documents`).then(({ data }) => data);
if (docSumary && docSumary.documents?.length > 0 && result.data.types && result.data.types.length > 0) {
const piTypes = result.data.types.join(",");
docSumary.documents = await Promise.all(docSumary.documents.map(async (doc) => {
const pi = await client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/documents/${doc.id}/pi?types=${piTypes}`).then(({ data }) => data);
if (pi?.documentNumber1) return {
...doc,
documentNumber: pi.documentNumber1
};
return doc;
}));
}
return docSumary;
};
//#endregion
//#region src/updateDocumentStatus.ts
const schema$1 = zod.z.object({
userId: zod.z.string().nonempty().guid(),
documentId: zod.z.number().nonnegative().int()
});
const updateDocumentStatus = async (client, userId, documentId, document) => {
const result = schema$1.safeParse({
userId,
documentId
});
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
return client.put(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/documents/${documentId}`, document).then(({ data }) => data);
};
//#endregion
//#region src/deleteDocument.ts
const schema = zod.z.object({
userId: zod.z.string().nonempty().guid(),
documentId: zod.z.number().positive().int()
});
const deleteDocument = async (client, userId, documentId) => {
const result = schema.safeParse({
userId,
documentId
});
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
await client.delete(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/documents/${documentId}`);
};
//#endregion
exports.createOrUpdateDocument = createOrUpdateDocument;
exports.deleteDocument = deleteDocument;
exports.getUserDocuments = getUserDocuments;
exports.personalInformationDocumentTypeSchema = personalInformationDocumentTypeSchema;
exports.personalInformationDocumentTypes = personalInformationDocumentTypes;
exports.updateDocumentStatus = updateDocumentStatus;