mypetbook-core 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/{utility/AppPaymentReportEntity.js → src/AppPaymentReportEntity.ts} +1 -5
- package/{utility/AppointmentEntity.js → src/AppointmentEntity.ts} +2 -2
- package/{utility/BillingReportEntity.js → src/BillingReportEntity.ts} +1 -5
- package/{utility/DataReportEntity.js → src/DataReportEntity.ts} +2 -2
- package/{utility/DisableSlotEntity.js → src/DisableSlotEntity.ts} +2 -2
- package/{utility/DoctorEntity.js → src/DoctorEntity.ts} +0 -6
- package/{utility/MedicalCardUploadEntity.js → src/MedicalCardUploadEntity.ts} +1 -1
- package/{utility/NotificationEntity.js → src/NotificationEntity.ts} +1 -1
- package/{utility/NotificationUploadEntity.js → src/NotificationUploadEntity.ts} +1 -1
- package/{utility/ParentDoctorEntity.js → src/ParentDoctorEntity.ts} +1 -1
- package/{utility/ParentEntity.js → src/ParentEntity.ts} +1 -1
- package/{utility/ParentReportEntity.js → src/ParentReportEntity.ts} +1 -1
- package/{utility/PetEntity.js → src/PetEntity.ts} +3 -3
- package/{utility/PrescriptionUploadEntity.js → src/PrescriptionUploadEntity.ts} +1 -1
- package/{utility/ProductEntity.js → src/ProductEntity.ts} +3 -3
- package/{utility/RecordingEntity.js → src/RecordingEntity.ts} +1 -1
- package/{utility/ReportUploadEntity.js → src/ReportUploadEntity.ts} +1 -1
- package/{utility/SystemSettingEntity.js → src/SystemSettingEntity.ts} +1 -1
- package/{utility/TimeSlotEntity.js → src/TimeSlotEntity.ts} +4 -4
- package/{utility/TreatmentEntity.js → src/TreatmentEntity.ts} +4 -4
- package/{utility/TreatmentRecordingEntity.js → src/TreatmentRecordingEntity.ts} +1 -1
- package/{utility/TreatmentReportEntity.js → src/TreatmentReportEntity.ts} +1 -1
- package/{utility/UserEntity.js → src/UserEntity.ts} +1 -1
- package/src/index.ts +0 -0
- package/index.js +0 -4
- package/utility/storageblob.js +0 -633
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mypetbook-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "This contain all the entity model for the mypetbook",
|
|
5
|
-
"main": "index.js",
|
|
5
|
+
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
8
|
},
|
|
@@ -18,11 +18,7 @@ const appPaymentReportSchema = new Schema({
|
|
|
18
18
|
razorPayId: { type: String }
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
const AppPaymentReport = mongoose.model(
|
|
21
|
+
export const AppPaymentReport = mongoose.model(
|
|
22
22
|
"AppPaymentReport",
|
|
23
23
|
appPaymentReportSchema
|
|
24
24
|
);
|
|
25
|
-
|
|
26
|
-
module.exports = {
|
|
27
|
-
AppPaymentReport,
|
|
28
|
-
};
|
|
@@ -16,7 +16,7 @@ const CategoryType = [
|
|
|
16
16
|
];
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
const AppointmentStatus = {
|
|
19
|
+
export const AppointmentStatus = {
|
|
20
20
|
APPOINTMENT_BOOKED: 'APPOINTMENT_BOOKED',
|
|
21
21
|
CHECKED_INTO_CLINIC: 'CHECKED_INTO_CLINIC',
|
|
22
22
|
IN_PROGRESS: 'IN_PROGRESS',
|
|
@@ -76,7 +76,7 @@ const appointmentSchema = new Schema({
|
|
|
76
76
|
console.info("customeStatiscMethod")
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
const Appointment = mongoose.model("Appointment", appointmentSchema);
|
|
79
|
+
export const Appointment = mongoose.model("Appointment", appointmentSchema);
|
|
80
80
|
|
|
81
81
|
|
|
82
82
|
module.exports = {
|
|
@@ -28,11 +28,7 @@ const billingReportSchema = new Schema({
|
|
|
28
28
|
atHomeVaccines: { type: Number },
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
-
const BillingReport = mongoose.model(
|
|
31
|
+
export const BillingReport = mongoose.model(
|
|
32
32
|
"BillingReport",
|
|
33
33
|
billingReportSchema
|
|
34
34
|
);
|
|
35
|
-
|
|
36
|
-
module.exports = {
|
|
37
|
-
BillingReport,
|
|
38
|
-
};
|
|
@@ -63,7 +63,7 @@ const yearlyDataSchema = new Schema({
|
|
|
63
63
|
},
|
|
64
64
|
toJSON: { virtuals: true },
|
|
65
65
|
});
|
|
66
|
-
const YearlyData = mongoose.model("YearlyData", yearlyDataSchema);
|
|
66
|
+
export const YearlyData = mongoose.model("YearlyData", yearlyDataSchema);
|
|
67
67
|
|
|
68
68
|
|
|
69
69
|
const billingSchema = new Schema({
|
|
@@ -84,7 +84,7 @@ const billingSchema = new Schema({
|
|
|
84
84
|
}
|
|
85
85
|
);
|
|
86
86
|
|
|
87
|
-
const Billing = mongoose.model("Billing", billingSchema);
|
|
87
|
+
export const Billing = mongoose.model("Billing", billingSchema);
|
|
88
88
|
|
|
89
89
|
module.exports = {
|
|
90
90
|
Billing,
|
|
@@ -2,7 +2,7 @@ const mongoose = require("mongoose");
|
|
|
2
2
|
const { DoctorSlot, SlotTypeEnum, SlotType } = require("./TimeSlotEntity");
|
|
3
3
|
|
|
4
4
|
const Schema = mongoose.Schema;
|
|
5
|
-
const ServiceLocation={
|
|
5
|
+
export const ServiceLocation={
|
|
6
6
|
CLINIC : "clinic",
|
|
7
7
|
HOME : "home"
|
|
8
8
|
}
|
|
@@ -38,7 +38,7 @@ const disableSlotSchema = new Schema({
|
|
|
38
38
|
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
-
const DisableSlot = mongoose.model("DisableSlot", disableSlotSchema);
|
|
41
|
+
export const DisableSlot = mongoose.model("DisableSlot", disableSlotSchema);
|
|
42
42
|
|
|
43
43
|
|
|
44
44
|
|
|
@@ -45,7 +45,7 @@ const medicalCardUploadSchema = new Schema({
|
|
|
45
45
|
toJSON: { virtuals: true },
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
const MedicalCardUpload = mongoose.model("MedicalCardUpload", medicalCardUploadSchema);
|
|
48
|
+
export const MedicalCardUpload = mongoose.model("MedicalCardUpload", medicalCardUploadSchema);
|
|
49
49
|
|
|
50
50
|
module.exports = {
|
|
51
51
|
MedicalCardUpload
|
|
@@ -17,7 +17,7 @@ const notificationUploadSchema = new Schema({
|
|
|
17
17
|
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
-
const NotificationUpload = mongoose.model("NotificationUpload", notificationUploadSchema);
|
|
20
|
+
export const NotificationUpload = mongoose.model("NotificationUpload", notificationUploadSchema);
|
|
21
21
|
|
|
22
22
|
module.exports = {
|
|
23
23
|
NotificationUpload
|
|
@@ -23,7 +23,7 @@ const parentDoctorSchema = new Schema({
|
|
|
23
23
|
console.info("customeStatiscMethod")
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
const ParentDoctor = mongoose.model("ParentDoctorMap", parentDoctorSchema);
|
|
26
|
+
export const ParentDoctor = mongoose.model("ParentDoctorMap", parentDoctorSchema);
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
module.exports = {
|
|
@@ -21,9 +21,9 @@ const petImagesSchema = Schema(
|
|
|
21
21
|
}
|
|
22
22
|
);
|
|
23
23
|
|
|
24
|
-
const PetImage = mongoose.model("PetImage", petImagesSchema);
|
|
24
|
+
export const PetImage = mongoose.model("PetImage", petImagesSchema);
|
|
25
25
|
|
|
26
|
-
const AnimalType = {
|
|
26
|
+
export const AnimalType = {
|
|
27
27
|
DOG: "Dog",
|
|
28
28
|
CAT: "Cat",
|
|
29
29
|
OTHER: "Other",
|
|
@@ -65,7 +65,7 @@ const petSchema = new Schema(
|
|
|
65
65
|
}
|
|
66
66
|
);
|
|
67
67
|
|
|
68
|
-
const Pet = mongoose.model("Pet", petSchema);
|
|
68
|
+
export const Pet = mongoose.model("Pet", petSchema);
|
|
69
69
|
|
|
70
70
|
module.exports = {
|
|
71
71
|
Pet,
|
|
@@ -45,7 +45,7 @@ const prescriptionUploadSchema = new Schema({
|
|
|
45
45
|
toJSON: { virtuals: true },
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
const PrescriptionUpload = mongoose.model("PrescriptionUpload", prescriptionUploadSchema);
|
|
48
|
+
export const PrescriptionUpload = mongoose.model("PrescriptionUpload", prescriptionUploadSchema);
|
|
49
49
|
|
|
50
50
|
module.exports = {
|
|
51
51
|
PrescriptionUpload
|
|
@@ -2,7 +2,7 @@ const mongoose = require('mongoose');
|
|
|
2
2
|
|
|
3
3
|
const Schema = mongoose.Schema;
|
|
4
4
|
|
|
5
|
-
const Category = {
|
|
5
|
+
export const Category = {
|
|
6
6
|
Vaccines: "Vaccines",
|
|
7
7
|
Medicines: "Medicines",
|
|
8
8
|
Pet_Products: "Pet_Products",
|
|
@@ -12,7 +12,7 @@ const Category = {
|
|
|
12
12
|
Consultancy: "Consultancy",
|
|
13
13
|
OTHER: "Other"
|
|
14
14
|
};
|
|
15
|
-
const CategoryEnum = [
|
|
15
|
+
export const CategoryEnum = [
|
|
16
16
|
Category.Vaccines,
|
|
17
17
|
Category.Medicines,
|
|
18
18
|
Category.Pet_Products,
|
|
@@ -60,7 +60,7 @@ productSchema.pre('save', function preSave(next){
|
|
|
60
60
|
something.updatedAt = Date.now();
|
|
61
61
|
next();
|
|
62
62
|
});
|
|
63
|
-
const Product = mongoose.model("Product", productSchema);
|
|
63
|
+
export const Product = mongoose.model("Product", productSchema);
|
|
64
64
|
|
|
65
65
|
|
|
66
66
|
|
|
@@ -47,7 +47,7 @@ const reportUploadSchema = new Schema({
|
|
|
47
47
|
toJSON: { virtuals: true },
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
-
const ReportUpload = mongoose.model("ReportUpload", reportUploadSchema);
|
|
50
|
+
export const ReportUpload = mongoose.model("ReportUpload", reportUploadSchema);
|
|
51
51
|
|
|
52
52
|
module.exports = {
|
|
53
53
|
ReportUpload
|
|
@@ -26,7 +26,7 @@ const systemSettingSchema = new Schema({
|
|
|
26
26
|
console.info("customeStatiscMethod")
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
const SystemSetting = mongoose.model("SystemSetting", systemSettingSchema);
|
|
29
|
+
export const SystemSetting = mongoose.model("SystemSetting", systemSettingSchema);
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
module.exports = {
|
|
@@ -12,15 +12,15 @@ const timeSlotSchema = new Schema({
|
|
|
12
12
|
title:{ type: String},
|
|
13
13
|
description:{ type: String},
|
|
14
14
|
});
|
|
15
|
-
const TimeSlot = mongoose.model("TimeSlot", timeSlotSchema);
|
|
15
|
+
export const TimeSlot = mongoose.model("TimeSlot", timeSlotSchema);
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
const SlotType={
|
|
18
|
+
export const SlotType={
|
|
19
19
|
EVENING : "evening",
|
|
20
20
|
DAY : "day",
|
|
21
21
|
NONE: "none"
|
|
22
22
|
}
|
|
23
|
-
const SlotTypeEnum =[
|
|
23
|
+
export const SlotTypeEnum =[
|
|
24
24
|
SlotType.DAY,
|
|
25
25
|
SlotType.EVENING,
|
|
26
26
|
SlotType.NONE
|
|
@@ -47,7 +47,7 @@ const doctorSlotSchema = new Schema({
|
|
|
47
47
|
default: SlotType.NONE
|
|
48
48
|
},
|
|
49
49
|
});
|
|
50
|
-
const DoctorSlot = mongoose.model("DoctorSlot", doctorSlotSchema);
|
|
50
|
+
export const DoctorSlot = mongoose.model("DoctorSlot", doctorSlotSchema);
|
|
51
51
|
|
|
52
52
|
|
|
53
53
|
|
|
@@ -2,12 +2,12 @@ const mongoose = require("mongoose");
|
|
|
2
2
|
|
|
3
3
|
const Schema = mongoose.Schema;
|
|
4
4
|
|
|
5
|
-
const TreatmentStatus = {
|
|
5
|
+
export const TreatmentStatus = {
|
|
6
6
|
TREATMENT_DRAFT: "TREATMENT_DRAFT",
|
|
7
7
|
TREATMENT_SAVE: "TREATMENT_SAVE",
|
|
8
8
|
TREATMENT_READ: "TREATMENT_READ",
|
|
9
9
|
};
|
|
10
|
-
const TreatmentEnum = [
|
|
10
|
+
export const TreatmentEnum = [
|
|
11
11
|
TreatmentStatus.TREATMENT_DRAFT,
|
|
12
12
|
TreatmentStatus.TREATMENT_SAVE,
|
|
13
13
|
TreatmentStatus.TREATMENT_READ,
|
|
@@ -60,7 +60,7 @@ const treatmentSchema = new Schema({
|
|
|
60
60
|
toJSON: { virtuals: true },
|
|
61
61
|
});
|
|
62
62
|
|
|
63
|
-
const Treatment = mongoose.model("Treatment", treatmentSchema);
|
|
63
|
+
export const Treatment = mongoose.model("Treatment", treatmentSchema);
|
|
64
64
|
|
|
65
65
|
const treatmentItemSchema = new Schema({
|
|
66
66
|
treatment: { type:mongoose.Schema.ObjectId, ref: "Treatment", index: true, required: true },
|
|
@@ -111,7 +111,7 @@ treatmentItemSchema.index(
|
|
|
111
111
|
{ treatment: 1, pet: 1, product: 1 },
|
|
112
112
|
{ unique: true }
|
|
113
113
|
);
|
|
114
|
-
const TreatmentItem = mongoose.model("TreatmentItem", treatmentItemSchema);
|
|
114
|
+
export const TreatmentItem = mongoose.model("TreatmentItem", treatmentItemSchema);
|
|
115
115
|
|
|
116
116
|
module.exports = {
|
|
117
117
|
Treatment,
|
|
@@ -11,7 +11,7 @@ const treatmentRecordingSchema = new Schema({
|
|
|
11
11
|
fileNo: Number
|
|
12
12
|
});
|
|
13
13
|
|
|
14
|
-
const TreatmentRecording = mongoose.model("TreatmentRecording", treatmentRecordingSchema);
|
|
14
|
+
export const TreatmentRecording = mongoose.model("TreatmentRecording", treatmentRecordingSchema);
|
|
15
15
|
|
|
16
16
|
module.exports = {
|
|
17
17
|
TreatmentRecording
|
package/src/index.ts
ADDED
|
File without changes
|
package/index.js
DELETED
package/utility/storageblob.js
DELETED
|
@@ -1,633 +0,0 @@
|
|
|
1
|
-
const { app } = require("@azure/functions");
|
|
2
|
-
const jwt = require("jsonwebtoken");
|
|
3
|
-
|
|
4
|
-
const formidable = require("formidable");
|
|
5
|
-
const multipart = require("parse-multipart");
|
|
6
|
-
const pkgcloud = require("pkgcloud");
|
|
7
|
-
const { Readable } = require("stream");
|
|
8
|
-
|
|
9
|
-
//const { AzureFunction, Context, HttpRequest } = require('@azure/functions');
|
|
10
|
-
const { BlobServiceClient } = require('@azure/storage-blob');
|
|
11
|
-
const { Pet } = require("./PetEntity");
|
|
12
|
-
const { Parent } = require("./ParentEntity");
|
|
13
|
-
const { Doctor } = require("./DoctorEntity");
|
|
14
|
-
|
|
15
|
-
const petContainer = process.env.STORAGE_PET_IMAGE;
|
|
16
|
-
const petOwnerContainer = process.env.STORAGE_PET_OWNER_IMAGE;
|
|
17
|
-
const blobServiceClient = BlobServiceClient.fromConnectionString(process.env.AZURE_CONNECTION_STRING);
|
|
18
|
-
|
|
19
|
-
const collDoctor = "doctors";
|
|
20
|
-
const collParents = "parents";
|
|
21
|
-
const collPet = "pets";
|
|
22
|
-
const petImageCount = process.env.PET_IMAGE_COUNT;
|
|
23
|
-
const MYPETBOOK_PET_IMAGE_BLOCK = process.env.MYPETBOOK_PET_IMAGE_BLOCK;
|
|
24
|
-
const MYPETBOOK_OWNER_IMAGE_BLOCK = process.env.MYPETBOOK_OWNER_IMAGE_BLOCK;
|
|
25
|
-
|
|
26
|
-
app.http("uploadOwnerId", {
|
|
27
|
-
methods: ["POST"],
|
|
28
|
-
route: "upload/owner/{id}",
|
|
29
|
-
authLevel: "anonymous",
|
|
30
|
-
handler: async (request, context) => {
|
|
31
|
-
try {
|
|
32
|
-
const token =
|
|
33
|
-
request.headers.get("authorization") &&
|
|
34
|
-
request.headers.get("authorization").split(" ")[1];
|
|
35
|
-
|
|
36
|
-
if (!token) {
|
|
37
|
-
return {
|
|
38
|
-
status: 401,
|
|
39
|
-
body: "Unauthorized",
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
const user = jwt.verify(token, process.env.JWT_SECRET);
|
|
43
|
-
|
|
44
|
-
if (user) {
|
|
45
|
-
const id = request.params.id;
|
|
46
|
-
const name = await request.arrayBuffer();
|
|
47
|
-
const h = request.headers.get("content-type");
|
|
48
|
-
const boundary = multipart.getBoundary(h);
|
|
49
|
-
if (boundary) {
|
|
50
|
-
const files = multipart.Parse(Buffer.from(name), boundary);
|
|
51
|
-
if (files && files.length > 0) {
|
|
52
|
-
const azureClient = pkgcloud.storage.createClient({
|
|
53
|
-
provider: "azure",
|
|
54
|
-
storageAccount: process.env.STORAGE_ACCOUNT, // Name of your storage account
|
|
55
|
-
storageAccessKey: process.env.STORAGE_ACCESS_KEY, // Access key for storage account
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
const images = [];
|
|
59
|
-
const file = files[0];
|
|
60
|
-
const imageName = id;
|
|
61
|
-
const ext = file.filename.split(".");
|
|
62
|
-
const extFinal = ext[ext.length - 1];
|
|
63
|
-
const total = Buffer.byteLength(file.data);
|
|
64
|
-
const option = {
|
|
65
|
-
container: petOwnerContainer,
|
|
66
|
-
remote: imageName + "." + extFinal,
|
|
67
|
-
size: total,
|
|
68
|
-
contentType: file.type,
|
|
69
|
-
};
|
|
70
|
-
var writeStream = azureClient.upload(option);
|
|
71
|
-
const stream = Readable.from(file.data);
|
|
72
|
-
const data = await stream.pipe(writeStream);
|
|
73
|
-
images.push({
|
|
74
|
-
fileName: file.filename,
|
|
75
|
-
uploadName: imageName + "." + extFinal,
|
|
76
|
-
uploadImageUrl:
|
|
77
|
-
MYPETBOOK_OWNER_IMAGE_BLOCK + imageName + "." + extFinal,
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
const updateDoc = {
|
|
81
|
-
$set: {
|
|
82
|
-
images,
|
|
83
|
-
user_image: imageName + "." + extFinal,
|
|
84
|
-
},
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
const result = await Parent.findByIdAndUpdate(id, updateDoc);
|
|
88
|
-
|
|
89
|
-
return {
|
|
90
|
-
status: 201,
|
|
91
|
-
body: JSON.stringify({
|
|
92
|
-
isSuccess: true,
|
|
93
|
-
result: " Processing the file",
|
|
94
|
-
updateDoc,
|
|
95
|
-
}),
|
|
96
|
-
headers: {
|
|
97
|
-
"Content-Type": "application/json",
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
} else {
|
|
101
|
-
return {
|
|
102
|
-
status: 201,
|
|
103
|
-
body: JSON.stringify({
|
|
104
|
-
isSuccess: true,
|
|
105
|
-
result: "File not found",
|
|
106
|
-
}),
|
|
107
|
-
headers: {
|
|
108
|
-
"Content-Type": "application/json",
|
|
109
|
-
},
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
} else {
|
|
113
|
-
return {
|
|
114
|
-
status: 201,
|
|
115
|
-
body: JSON.stringify({
|
|
116
|
-
isSuccess: true,
|
|
117
|
-
result: "Error Processing the file",
|
|
118
|
-
}),
|
|
119
|
-
headers: {
|
|
120
|
-
"Content-Type": "application/json",
|
|
121
|
-
},
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
} catch (err) {
|
|
126
|
-
return {
|
|
127
|
-
status: 500,
|
|
128
|
-
body: JSON.stringify({
|
|
129
|
-
isSuccess: false,
|
|
130
|
-
message: `Error occurred - ${err.message || err}`,
|
|
131
|
-
}),
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
app.http("uploadDoctorId", {
|
|
138
|
-
methods: ["POST"],
|
|
139
|
-
route: "upload/doctor/{id}",
|
|
140
|
-
authLevel: "anonymous",
|
|
141
|
-
handler: async (request, context) => {
|
|
142
|
-
try {
|
|
143
|
-
const token =
|
|
144
|
-
request.headers.get("authorization") &&
|
|
145
|
-
request.headers.get("authorization").split(" ")[1];
|
|
146
|
-
|
|
147
|
-
if (!token) {
|
|
148
|
-
return {
|
|
149
|
-
status: 401,
|
|
150
|
-
body: "Unauthorized",
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
const user = jwt.verify(token, process.env.JWT_SECRET);
|
|
154
|
-
|
|
155
|
-
if (user) {
|
|
156
|
-
const id = request.params.id;
|
|
157
|
-
const name = await request.arrayBuffer();
|
|
158
|
-
const h = request.headers.get("content-type");
|
|
159
|
-
const boundary = multipart.getBoundary(h);
|
|
160
|
-
if (boundary) {
|
|
161
|
-
const files = multipart.Parse(Buffer.from(name), boundary);
|
|
162
|
-
if (files && files.length > 0) {
|
|
163
|
-
const azureClient = pkgcloud.storage.createClient({
|
|
164
|
-
provider: "azure",
|
|
165
|
-
storageAccount: process.env.STORAGE_ACCOUNT, // Name of your storage account
|
|
166
|
-
storageAccessKey: process.env.STORAGE_ACCESS_KEY, // Access key for storage account
|
|
167
|
-
});
|
|
168
|
-
var count = 0;
|
|
169
|
-
const images = [];
|
|
170
|
-
const file = files[0];
|
|
171
|
-
const imageName = id;
|
|
172
|
-
const ext = file.filename.split(".");
|
|
173
|
-
const extFinal = ext[ext.length - 1];
|
|
174
|
-
const total = Buffer.byteLength(file.data);
|
|
175
|
-
const option = {
|
|
176
|
-
container: petOwnerContainer,
|
|
177
|
-
remote: imageName + "." + extFinal,
|
|
178
|
-
size: total,
|
|
179
|
-
contentType: file.type,
|
|
180
|
-
};
|
|
181
|
-
var writeStream = azureClient.upload(option);
|
|
182
|
-
const stream = Readable.from(file.data);
|
|
183
|
-
const data = await stream.pipe(writeStream);
|
|
184
|
-
images.push({
|
|
185
|
-
fileName: file.filename,
|
|
186
|
-
uploadName: imageName + "." + extFinal,
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
const updateDoc = {
|
|
190
|
-
$set: {
|
|
191
|
-
images,
|
|
192
|
-
user_image: imageName + "." + extFinal,
|
|
193
|
-
},
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
const doctor = await Doctor.findById(id);
|
|
197
|
-
doctor.user_image = imageName + "." + extFinal;
|
|
198
|
-
doctor.images = images;
|
|
199
|
-
|
|
200
|
-
const result = await doctor.save();
|
|
201
|
-
|
|
202
|
-
return {
|
|
203
|
-
status: 201,
|
|
204
|
-
body: JSON.stringify({
|
|
205
|
-
isSuccess: true,
|
|
206
|
-
result: " Processing the file",
|
|
207
|
-
updateDoc,
|
|
208
|
-
}),
|
|
209
|
-
headers: {
|
|
210
|
-
"Content-Type": "application/json",
|
|
211
|
-
},
|
|
212
|
-
};
|
|
213
|
-
} else {
|
|
214
|
-
return {
|
|
215
|
-
status: 201,
|
|
216
|
-
body: JSON.stringify({
|
|
217
|
-
isSuccess: true,
|
|
218
|
-
result: "File not found",
|
|
219
|
-
}),
|
|
220
|
-
headers: {
|
|
221
|
-
"Content-Type": "application/json",
|
|
222
|
-
},
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
} else {
|
|
226
|
-
return {
|
|
227
|
-
status: 201,
|
|
228
|
-
body: JSON.stringify({
|
|
229
|
-
isSuccess: true,
|
|
230
|
-
result: "Error Processing the file",
|
|
231
|
-
}),
|
|
232
|
-
headers: {
|
|
233
|
-
"Content-Type": "application/json",
|
|
234
|
-
},
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
} catch (err) {
|
|
239
|
-
return {
|
|
240
|
-
status: 500,
|
|
241
|
-
body: JSON.stringify({
|
|
242
|
-
isSuccess: false,
|
|
243
|
-
message: `Error occurred - ${err.message || err}`,
|
|
244
|
-
}),
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
},
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
app.http("uploadPetIdCount", {
|
|
251
|
-
methods: ["POST"],
|
|
252
|
-
route: "upload/pet/{id}/{count:int?}",
|
|
253
|
-
authLevel: "anonymous",
|
|
254
|
-
handler: async (request, context) => {
|
|
255
|
-
try {
|
|
256
|
-
const token =
|
|
257
|
-
request.headers.get("authorization") &&
|
|
258
|
-
request.headers.get("authorization").split(" ")[1];
|
|
259
|
-
|
|
260
|
-
if (!token) {
|
|
261
|
-
return {
|
|
262
|
-
status: 401,
|
|
263
|
-
body: "Unauthorized",
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
const user = jwt.verify(token, process.env.JWT_SECRET);
|
|
267
|
-
|
|
268
|
-
if (user) {
|
|
269
|
-
const id = request.params.id;
|
|
270
|
-
var count = request.params.count;
|
|
271
|
-
const name = await request.arrayBuffer();
|
|
272
|
-
const h = request.headers.get("content-type");
|
|
273
|
-
const boundary = multipart.getBoundary(h);
|
|
274
|
-
if (boundary) {
|
|
275
|
-
const files = multipart.Parse(Buffer.from(name), boundary);
|
|
276
|
-
if (files && files.length > 0) {
|
|
277
|
-
if (files.length > petImageCount) {
|
|
278
|
-
return {
|
|
279
|
-
status: 201,
|
|
280
|
-
body: JSON.stringify({
|
|
281
|
-
isSuccess: true,
|
|
282
|
-
result: "Error: Maximum file upload is " + petImageCount,
|
|
283
|
-
}),
|
|
284
|
-
headers: {
|
|
285
|
-
"Content-Type": "application/json",
|
|
286
|
-
},
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
const azureClient = pkgcloud.storage.createClient({
|
|
291
|
-
provider: "azure",
|
|
292
|
-
storageAccount: process.env.STORAGE_ACCOUNT, // Name of your storage account
|
|
293
|
-
storageAccessKey: process.env.STORAGE_ACCESS_KEY, // Access key for storage account
|
|
294
|
-
});
|
|
295
|
-
const images = [];
|
|
296
|
-
if (!count) {
|
|
297
|
-
count = 0;
|
|
298
|
-
for await (const file of files) {
|
|
299
|
-
const no = ++count;
|
|
300
|
-
const imageName = id + "_" + no;
|
|
301
|
-
const ext = file.filename.split(".");
|
|
302
|
-
const extFinal = ext[ext.length - 1];
|
|
303
|
-
const total = Buffer.byteLength(file.data);
|
|
304
|
-
const option = {
|
|
305
|
-
container: petContainer,
|
|
306
|
-
remote: imageName + "." + extFinal,
|
|
307
|
-
size: total,
|
|
308
|
-
contentType: file.type,
|
|
309
|
-
};
|
|
310
|
-
var writeStream = azureClient.upload(option);
|
|
311
|
-
const stream = Readable.from(file.data);
|
|
312
|
-
const data = await stream.pipe(writeStream);
|
|
313
|
-
|
|
314
|
-
images.push({
|
|
315
|
-
fileName: file.filename,
|
|
316
|
-
uploadName: imageName + "." + extFinal,
|
|
317
|
-
uploadImageUrl:
|
|
318
|
-
MYPETBOOK_PET_IMAGE_BLOCK + imageName + "." + extFinal,
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
console.log("images", images);
|
|
323
|
-
} else {
|
|
324
|
-
if (count > petImageCount) {
|
|
325
|
-
return {
|
|
326
|
-
status: 201,
|
|
327
|
-
body: JSON.stringify({
|
|
328
|
-
isSuccess: true,
|
|
329
|
-
result:
|
|
330
|
-
"Error: File number should be 1 to " + petImageCount,
|
|
331
|
-
}),
|
|
332
|
-
headers: {
|
|
333
|
-
"Content-Type": "application/json",
|
|
334
|
-
},
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
const file = files[0];
|
|
338
|
-
|
|
339
|
-
const no = count;
|
|
340
|
-
const imageName = id + "_" + no;
|
|
341
|
-
const ext = file.filename.split(".");
|
|
342
|
-
const extFinal = ext[ext.length - 1];
|
|
343
|
-
const total = Buffer.byteLength(file.data);
|
|
344
|
-
const option = {
|
|
345
|
-
container: petContainer,
|
|
346
|
-
remote: imageName + "." + extFinal,
|
|
347
|
-
size: total,
|
|
348
|
-
contentType: file.type,
|
|
349
|
-
};
|
|
350
|
-
var writeStream = azureClient.upload(option);
|
|
351
|
-
const stream = Readable.from(file.data);
|
|
352
|
-
const data = await stream.pipe(writeStream);
|
|
353
|
-
images.push({
|
|
354
|
-
fileName: file.filename,
|
|
355
|
-
uploadName: imageName + "." + extFinal,
|
|
356
|
-
uploadImageUrl:
|
|
357
|
-
MYPETBOOK_PET_IMAGE_BLOCK + imageName + "." + extFinal,
|
|
358
|
-
});
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
const updateDoc = {
|
|
363
|
-
$set: {
|
|
364
|
-
images,
|
|
365
|
-
user_image:images[0]?.uploadName
|
|
366
|
-
},
|
|
367
|
-
};
|
|
368
|
-
|
|
369
|
-
const result = await Pet.findByIdAndUpdate(id, updateDoc);
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
return {
|
|
373
|
-
status: 201,
|
|
374
|
-
body: JSON.stringify({
|
|
375
|
-
isSuccess: true,
|
|
376
|
-
updateDoc,
|
|
377
|
-
result
|
|
378
|
-
}),
|
|
379
|
-
headers: {
|
|
380
|
-
"Content-Type": "application/json",
|
|
381
|
-
},
|
|
382
|
-
};
|
|
383
|
-
} else {
|
|
384
|
-
return {
|
|
385
|
-
status: 201,
|
|
386
|
-
body: JSON.stringify({
|
|
387
|
-
isSuccess: true,
|
|
388
|
-
result: "File not found",
|
|
389
|
-
}),
|
|
390
|
-
headers: {
|
|
391
|
-
"Content-Type": "application/json",
|
|
392
|
-
},
|
|
393
|
-
};
|
|
394
|
-
}
|
|
395
|
-
} else {
|
|
396
|
-
return {
|
|
397
|
-
status: 201,
|
|
398
|
-
body: JSON.stringify({
|
|
399
|
-
isSuccess: true,
|
|
400
|
-
result: "Error Processing the file",
|
|
401
|
-
}),
|
|
402
|
-
headers: {
|
|
403
|
-
"Content-Type": "application/json",
|
|
404
|
-
},
|
|
405
|
-
};
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
} catch (err) {
|
|
409
|
-
return {
|
|
410
|
-
status: 500,
|
|
411
|
-
body: JSON.stringify({
|
|
412
|
-
isSuccess: false,
|
|
413
|
-
message: `Error occurred - ${err.message || err}`,
|
|
414
|
-
}),
|
|
415
|
-
};
|
|
416
|
-
}
|
|
417
|
-
},
|
|
418
|
-
});
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
app.http("downloadOwnerId", {
|
|
422
|
-
methods: ["GET"],
|
|
423
|
-
route: "download/owner/{id}",
|
|
424
|
-
authLevel: "anonymous",
|
|
425
|
-
handler: async (request, context) => {
|
|
426
|
-
try {
|
|
427
|
-
const token =
|
|
428
|
-
request.headers.get("authorization") &&
|
|
429
|
-
request.headers.get("authorization").split(" ")[1];
|
|
430
|
-
|
|
431
|
-
if (!token) {
|
|
432
|
-
return {
|
|
433
|
-
status: 401,
|
|
434
|
-
body: "Unauthorized",
|
|
435
|
-
};
|
|
436
|
-
}
|
|
437
|
-
const user = jwt.verify(token, process.env.JWT_SECRET);
|
|
438
|
-
|
|
439
|
-
if (user) {
|
|
440
|
-
const id = request.params.id;
|
|
441
|
-
const result = await Parent.findById(id);
|
|
442
|
-
|
|
443
|
-
const containerClient = blobServiceClient.getContainerClient(petOwnerContainer);
|
|
444
|
-
const blobClient = containerClient.getBlockBlobClient(result?.user_image);
|
|
445
|
-
|
|
446
|
-
const downloadBlockBlobResponse = await blobClient.download();
|
|
447
|
-
const content = await streamToBuffer(downloadBlockBlobResponse.readableStreamBody);
|
|
448
|
-
|
|
449
|
-
return {
|
|
450
|
-
body: content,
|
|
451
|
-
headers: {
|
|
452
|
-
'Content-Type': 'image/png', // Adjust the content type based on your image type
|
|
453
|
-
}
|
|
454
|
-
};
|
|
455
|
-
|
|
456
|
-
}else{
|
|
457
|
-
return {
|
|
458
|
-
status: 401,
|
|
459
|
-
body: "Unauthorized",
|
|
460
|
-
};
|
|
461
|
-
}
|
|
462
|
-
} catch (err) {
|
|
463
|
-
return {
|
|
464
|
-
status: 500,
|
|
465
|
-
body: JSON.stringify({
|
|
466
|
-
isSuccess: false,
|
|
467
|
-
message: `Error occurred - ${err.message || err}`,
|
|
468
|
-
}),
|
|
469
|
-
};
|
|
470
|
-
}
|
|
471
|
-
},
|
|
472
|
-
});
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
app.http("downloadDoctorId", {
|
|
476
|
-
methods: ["GET"],
|
|
477
|
-
route: "download/doctor/{id}",
|
|
478
|
-
authLevel: "anonymous",
|
|
479
|
-
handler: async (request, context) => {
|
|
480
|
-
try {
|
|
481
|
-
const token =
|
|
482
|
-
request.headers.get("authorization") &&
|
|
483
|
-
request.headers.get("authorization").split(" ")[1];
|
|
484
|
-
|
|
485
|
-
if (!token) {
|
|
486
|
-
return {
|
|
487
|
-
status: 401,
|
|
488
|
-
body: "Unauthorized",
|
|
489
|
-
};
|
|
490
|
-
}
|
|
491
|
-
const user = jwt.verify(token, process.env.JWT_SECRET);
|
|
492
|
-
|
|
493
|
-
if (user) {
|
|
494
|
-
const id = request.params.id;
|
|
495
|
-
const result = await Doctor.findById(id);
|
|
496
|
-
|
|
497
|
-
const containerClient = blobServiceClient.getContainerClient(petOwnerContainer);
|
|
498
|
-
const blobClient = containerClient.getBlockBlobClient(result?.user_image);
|
|
499
|
-
|
|
500
|
-
const downloadBlockBlobResponse = await blobClient.download();
|
|
501
|
-
const content = await streamToBuffer(downloadBlockBlobResponse.readableStreamBody);
|
|
502
|
-
|
|
503
|
-
return {
|
|
504
|
-
body: content,
|
|
505
|
-
headers: {
|
|
506
|
-
'Content-Type': 'image/png', // Adjust the content type based on your image type
|
|
507
|
-
}
|
|
508
|
-
};
|
|
509
|
-
|
|
510
|
-
}else{
|
|
511
|
-
return {
|
|
512
|
-
status: 401,
|
|
513
|
-
body: "Unauthorized",
|
|
514
|
-
};
|
|
515
|
-
}
|
|
516
|
-
} catch (err) {
|
|
517
|
-
return {
|
|
518
|
-
status: 500,
|
|
519
|
-
body: JSON.stringify({
|
|
520
|
-
isSuccess: false,
|
|
521
|
-
message: `Error occurred - ${err.message || err}`,
|
|
522
|
-
}),
|
|
523
|
-
};
|
|
524
|
-
}
|
|
525
|
-
},
|
|
526
|
-
});
|
|
527
|
-
|
|
528
|
-
app.http("uploadPetId", {
|
|
529
|
-
methods: ["GET"],
|
|
530
|
-
route: "download/pet/{id}",
|
|
531
|
-
authLevel: "anonymous",
|
|
532
|
-
handler: async (request, context) => {
|
|
533
|
-
try {
|
|
534
|
-
const token =
|
|
535
|
-
request.headers.get("authorization") &&
|
|
536
|
-
request.headers.get("authorization").split(" ")[1];
|
|
537
|
-
|
|
538
|
-
if (!token) {
|
|
539
|
-
return {
|
|
540
|
-
status: 401,
|
|
541
|
-
body: "Unauthorized",
|
|
542
|
-
};
|
|
543
|
-
}
|
|
544
|
-
const user = jwt.verify(token, process.env.JWT_SECRET);
|
|
545
|
-
|
|
546
|
-
if (user) {
|
|
547
|
-
const id = request.params.id;
|
|
548
|
-
const result = await Pet.findById(id);
|
|
549
|
-
|
|
550
|
-
const containerClient = blobServiceClient.getContainerClient(petOwnerContainer);
|
|
551
|
-
const blobClient = containerClient.getBlockBlobClient(result?.user_image);
|
|
552
|
-
|
|
553
|
-
const downloadBlockBlobResponse = await blobClient.download();
|
|
554
|
-
const content = await streamToBuffer(downloadBlockBlobResponse.readableStreamBody);
|
|
555
|
-
|
|
556
|
-
return {
|
|
557
|
-
body: content,
|
|
558
|
-
headers: {
|
|
559
|
-
'Content-Type': 'image/png', // Adjust the content type based on your image type
|
|
560
|
-
}
|
|
561
|
-
};
|
|
562
|
-
}else{
|
|
563
|
-
return {
|
|
564
|
-
status: 401,
|
|
565
|
-
body: "Unauthorized",
|
|
566
|
-
};
|
|
567
|
-
}
|
|
568
|
-
} catch (err) {
|
|
569
|
-
return {
|
|
570
|
-
status: 500,
|
|
571
|
-
body: JSON.stringify({
|
|
572
|
-
isSuccess: false,
|
|
573
|
-
message: `Error occurred - ${err.message || err}`,
|
|
574
|
-
}),
|
|
575
|
-
};
|
|
576
|
-
}
|
|
577
|
-
},
|
|
578
|
-
});
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
async function readRecording(container,id,fileNo){
|
|
586
|
-
try {
|
|
587
|
-
|
|
588
|
-
const client = pkgcloud.storage.createClient({
|
|
589
|
-
provider: "azure",
|
|
590
|
-
storageAccount: process.env.STORAGE_ACCOUNT, // Name of your storage account
|
|
591
|
-
storageAccessKey: process.env.STORAGE_ACCESS_KEY, // Access key for storage account
|
|
592
|
-
});
|
|
593
|
-
|
|
594
|
-
// const total2 = await files[0].data.byteLength();
|
|
595
|
-
const option = {
|
|
596
|
-
container: container,
|
|
597
|
-
remote: id+"-"+fileNo+".json",
|
|
598
|
-
contentType: "application/json",
|
|
599
|
-
}
|
|
600
|
-
console.info("option",option);
|
|
601
|
-
var readStream = await client.download(option);
|
|
602
|
-
const result = await streamToString(readStream);
|
|
603
|
-
return JSON.parse( result);
|
|
604
|
-
|
|
605
|
-
} catch (error) {
|
|
606
|
-
res.json({
|
|
607
|
-
message: "Error uploading JSON data"
|
|
608
|
-
});
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
function streamToString (stream) {
|
|
613
|
-
const chunks = []
|
|
614
|
-
return new Promise((resolve, reject) => {
|
|
615
|
-
stream.on('data', chunk => chunks.push(chunk))
|
|
616
|
-
stream.on('error', reject)
|
|
617
|
-
stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')))
|
|
618
|
-
})
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
// Helper function to convert stream to buffer
|
|
622
|
-
async function streamToBuffer(readableStream) {
|
|
623
|
-
return new Promise((resolve, reject) => {
|
|
624
|
-
const chunks = [];
|
|
625
|
-
readableStream.on('data', (data) => {
|
|
626
|
-
chunks.push(data instanceof Buffer ? data : Buffer.from(data));
|
|
627
|
-
});
|
|
628
|
-
readableStream.on('end', () => {
|
|
629
|
-
resolve(Buffer.concat(chunks));
|
|
630
|
-
});
|
|
631
|
-
readableStream.on('error', reject);
|
|
632
|
-
});
|
|
633
|
-
}
|