Spaces:
Runtime error
Runtime error
remove pdf url and add file in upload
Browse files- package.json +1 -1
- src/shared/services/bills.service.ts +26 -4
- src/shared/services/propertyware.service.ts +1 -1
- yarn.lock +12 -1
package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
| 14 |
"dotenv": "^16.4.5",
|
| 15 |
"express": "^4.19.2",
|
| 16 |
"express-validator": "^7.1.0",
|
| 17 |
-
"form-data": "^4.0.
|
| 18 |
"jsonwebtoken": "^9.0.2",
|
| 19 |
"multer": "^1.4.5-lts.1",
|
| 20 |
"mysql2": "^3.10.2",
|
|
|
|
| 14 |
"dotenv": "^16.4.5",
|
| 15 |
"express": "^4.19.2",
|
| 16 |
"express-validator": "^7.1.0",
|
| 17 |
+
"form-data": "^4.0.1",
|
| 18 |
"jsonwebtoken": "^9.0.2",
|
| 19 |
"multer": "^1.4.5-lts.1",
|
| 20 |
"mysql2": "^3.10.2",
|
src/shared/services/bills.service.ts
CHANGED
|
@@ -7,6 +7,10 @@ import { formatDate } from '../../utils/dataUtils';
|
|
| 7 |
import ErrorLog from '../../models/errorLog';
|
| 8 |
import { createAuditLog } from '../../controllers/auditLog.controller';
|
| 9 |
import { updateInvoiceData } from '../../controllers/invoice/invoice.controller';
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
interface ErrorResponse {
|
| 12 |
response: {
|
|
@@ -64,10 +68,28 @@ export const syncInvoicesService = async (): Promise<string> => {
|
|
| 64 |
try {
|
| 65 |
|
| 66 |
// upload invoice file to propertyware
|
| 67 |
-
if (invoice.filename) {
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
}
|
| 72 |
|
| 73 |
} catch (error) {
|
|
|
|
| 7 |
import ErrorLog from '../../models/errorLog';
|
| 8 |
import { createAuditLog } from '../../controllers/auditLog.controller';
|
| 9 |
import { updateInvoiceData } from '../../controllers/invoice/invoice.controller';
|
| 10 |
+
import fs from 'fs';
|
| 11 |
+
import path from 'path';
|
| 12 |
+
import axios from 'axios';
|
| 13 |
+
import FormData from 'form-data';
|
| 14 |
|
| 15 |
interface ErrorResponse {
|
| 16 |
response: {
|
|
|
|
| 68 |
try {
|
| 69 |
|
| 70 |
// upload invoice file to propertyware
|
| 71 |
+
if (invoice.filename) {try {
|
| 72 |
+
const filePath = path.resolve('/tmp', invoice.filename); // Save to a temporary path
|
| 73 |
+
const { data } = await axios.get(invoice.pdf_url as string, { responseType: 'stream' });
|
| 74 |
+
|
| 75 |
+
const writer = fs.createWriteStream(filePath);
|
| 76 |
+
data.pipe(writer);
|
| 77 |
+
|
| 78 |
+
await new Promise((resolve, reject) => {
|
| 79 |
+
writer.on('finish', resolve);
|
| 80 |
+
writer.on('error', reject);
|
| 81 |
+
});
|
| 82 |
+
|
| 83 |
+
const formData = new FormData();
|
| 84 |
+
formData.append('file', fs.createReadStream(filePath), invoice.filename);
|
| 85 |
+
|
| 86 |
+
await uploadBill(response.id, formData);
|
| 87 |
+
|
| 88 |
+
fs.unlinkSync(filePath);
|
| 89 |
+
} catch (error) {
|
| 90 |
+
console.log("Invoice file upload failed: ", error);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
}
|
| 94 |
|
| 95 |
} catch (error) {
|
src/shared/services/propertyware.service.ts
CHANGED
|
@@ -66,7 +66,7 @@ export const createBill = async (params: unknown) => {
|
|
| 66 |
return response.data;
|
| 67 |
};
|
| 68 |
|
| 69 |
-
export const uploadBill = async (billId: string, params:
|
| 70 |
const response = await apiClientPW.post(`/docs?entityId=${billId}&entityType=BILL`, params, {
|
| 71 |
headers: {
|
| 72 |
'Content-Type': 'multipart/form-data'
|
|
|
|
| 66 |
return response.data;
|
| 67 |
};
|
| 68 |
|
| 69 |
+
export const uploadBill = async (billId: string, params: any) => {
|
| 70 |
const response = await apiClientPW.post(`/docs?entityId=${billId}&entityType=BILL`, params, {
|
| 71 |
headers: {
|
| 72 |
'Content-Type': 'multipart/form-data'
|
yarn.lock
CHANGED
|
@@ -3418,7 +3418,7 @@ __metadata:
|
|
| 3418 |
eslint-plugin-prettier: "npm:^5.1.3"
|
| 3419 |
express: "npm:^4.19.2"
|
| 3420 |
express-validator: "npm:^7.1.0"
|
| 3421 |
-
form-data: "npm:^4.0.
|
| 3422 |
jsonwebtoken: "npm:^9.0.2"
|
| 3423 |
multer: "npm:^1.4.5-lts.1"
|
| 3424 |
mysql2: "npm:^3.10.2"
|
|
@@ -3539,6 +3539,17 @@ __metadata:
|
|
| 3539 |
languageName: node
|
| 3540 |
linkType: hard
|
| 3541 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3542 |
"forwarded@npm:0.2.0":
|
| 3543 |
version: 0.2.0
|
| 3544 |
resolution: "forwarded@npm:0.2.0"
|
|
|
|
| 3418 |
eslint-plugin-prettier: "npm:^5.1.3"
|
| 3419 |
express: "npm:^4.19.2"
|
| 3420 |
express-validator: "npm:^7.1.0"
|
| 3421 |
+
form-data: "npm:^4.0.1"
|
| 3422 |
jsonwebtoken: "npm:^9.0.2"
|
| 3423 |
multer: "npm:^1.4.5-lts.1"
|
| 3424 |
mysql2: "npm:^3.10.2"
|
|
|
|
| 3539 |
languageName: node
|
| 3540 |
linkType: hard
|
| 3541 |
|
| 3542 |
+
"form-data@npm:^4.0.1":
|
| 3543 |
+
version: 4.0.1
|
| 3544 |
+
resolution: "form-data@npm:4.0.1"
|
| 3545 |
+
dependencies:
|
| 3546 |
+
asynckit: "npm:^0.4.0"
|
| 3547 |
+
combined-stream: "npm:^1.0.8"
|
| 3548 |
+
mime-types: "npm:^2.1.12"
|
| 3549 |
+
checksum: 10c0/bb102d570be8592c23f4ea72d7df9daa50c7792eb0cf1c5d7e506c1706e7426a4e4ae48a35b109e91c85f1c0ec63774a21ae252b66f4eb981cb8efef7d0463c8
|
| 3550 |
+
languageName: node
|
| 3551 |
+
linkType: hard
|
| 3552 |
+
|
| 3553 |
"forwarded@npm:0.2.0":
|
| 3554 |
version: 0.2.0
|
| 3555 |
resolution: "forwarded@npm:0.2.0"
|