feat: add migration script for generate token route

This commit is contained in:
prafull-opensignlabs
2024-01-16 17:43:42 +05:30
parent 9500b2d678
commit eefaf5fe50
6 changed files with 740 additions and 68 deletions
@@ -45,7 +45,7 @@ app.delete('/contact/:contact_id', deleteContact);
app.get('/contactlist', getContactList);
// create Document
app.post('/createdocument', createDocument);
app.post('/createdocument', upload.array('file', 1), createDocument);
// get Document on the basis of id
app.get('/document/:document_id', getDocument);
@@ -60,7 +60,7 @@ app.delete('/document/:document_id', deleteDocument);
app.get('/documentlist/:doctype', getDocumentList);
// create Template
app.post('/createtemplate', createTemplate);
app.post('/createtemplate',upload.array('file', 1), createTemplate);
// get template on the basis of id
app.get('/template/:template_id', getTemplate);
@@ -74,43 +74,3 @@ app.delete('/template/:template_id', deletedTemplate);
// get all types of documents on the basis of doctype
app.get('/templatelist', getTemplatetList);
app.post('/tempupload', upload.single('file'), async (req, res) => {
const name = req.body.name;
const note = req.body.note;
const description = req.body.description;
const fileFormat = req.body.fileFormat; // 'binary' or 'base64'
const filePath = req.body.filePath; // Path to the file
let fileData;
if (fileFormat === 'binary') {
// Read file content if the file is in binary format
fileData = fs.readFileSync(filePath);
} else if (fileFormat === 'base64') {
// Convert base64 data to binary
fileData = req.file ? req.file.buffer : null;
} else {
return res.status(400).json({ error: 'Invalid file format' });
}
// Create a Parse.File object
const file = new Parse.File('myfile', { base64: fileData.toString('base64') });
// Save the file to Parse Server
try {
await file.save();
} catch (error) {
console.error('Error saving file to Parse Server:', error);
return res.status(500).json({ error: 'Internal Server Error' });
}
// Perform any desired processing with the received data
// Respond to the client with the file URL
res.json({
name: name,
note: note,
description: description,
fileUrl: file.url(),
});
});