add createDocument from template functionality

This commit is contained in:
prafull-opensignlabs
2023-12-16 22:19:12 +05:30
parent cb4a94d036
commit ca6b4e7d82
5 changed files with 110 additions and 3 deletions
@@ -1002,4 +1002,63 @@ export const signPdfFun = async (
return response;
};
export const randomId = () => Math.floor(1000 + Math.random() * 9000);
export const randomId = () => Math.floor(1000 + Math.random() * 9000);
export const createDocument = async (template) => {
if (template && template.length > 0) {
const Doc = template[0];
let signers;
console.log("Doc.Placholders ", Doc)
if (Doc.Signers && Doc.Signers.length > 0) {
signers = Doc.Signers.map((x) => ({
__type: "Pointer",
className: "contracts_Contactbook",
objectId: x.objectId
}));
} else {
signers = [];
}
const data = {
Name: Doc.Name,
URL: Doc.URL,
SignedUrl: Doc.SignedUrl,
Description: Doc.Description,
Note: Doc.Note,
Placeholders: Doc.Placeholders,
ExtUserPtr: {
__type: "Pointer",
className: "contracts_Users",
objectId: Doc.ExtUserPtr.objectId
},
CreatedBy: {
__type: "Pointer",
className: "_User",
objectId: Doc.CreatedBy.objectId
},
Signers: signers
};
try {
const res = await axios.post(
`${localStorage.getItem("baseUrl")}classes/${localStorage.getItem(
"_appName"
)}_Document`,
data,
{
headers: {
"Content-Type": "application/json",
"X-Parse-Application-Id": localStorage.getItem("parseAppId"),
"X-Parse-Session-Token": localStorage.getItem("accesstoken")
}
}
);
if (res) {
console.log("res", res);
return { status: "success", id: res.data.objectId };
}
} catch (err) {
console.log("axois err ", err);
return { status: "error", id: "Something Went Wrong!" };
}
}
};