@internetderdinge/api 1.229.10 → 1.229.17
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/dist/src/accounts/accounts.controller.js +0 -1
- package/dist/src/config/config.js +0 -6
- package/dist/src/devices/devices.controller.js +1 -31
- package/dist/src/devices/devices.route.js +2 -33
- package/dist/src/devices/devices.service.js +0 -21
- package/dist/src/devices/devices.validation.js +3 -40
- package/dist/src/email/email.service.js +46 -39
- package/dist/src/index.js +18 -1
- package/dist/src/iotdevice/iotdevice.route.js +1 -1
- package/dist/src/iotdevice/iotdevice.service.js +23 -113
- package/dist/src/middlewares/auth.js +49 -2
- package/dist/src/middlewares/validateCurrentUser.js +2 -2
- package/dist/src/models/plugins/simplePopulate.js +1 -1
- package/dist/src/pdf/pdf.service.js +18 -19
- package/dist/src/users/users.schemas.js +2 -46
- package/dist/src/users/users.service.js +1 -0
- package/package.json +3 -2
- package/src/accounts/accounts.controller.ts +0 -1
- package/src/config/config.ts +0 -6
- package/src/devices/devices.controller.ts +0 -53
- package/src/devices/devices.route.ts +0 -39
- package/src/devices/devices.service.ts +0 -38
- package/src/devices/devices.validation.ts +9 -47
- package/src/email/email.service.ts +70 -43
- package/src/index.ts +18 -1
- package/src/iotdevice/iotdevice.route.ts +1 -1
- package/src/iotdevice/iotdevice.service.ts +34 -167
- package/src/middlewares/auth.ts +75 -2
- package/src/middlewares/validateCurrentUser.ts +2 -2
- package/src/models/plugins/simplePopulate.ts +1 -1
- package/src/pdf/pdf.service.ts +36 -31
- package/src/users/users.schemas.ts +3 -50
- package/src/users/users.service.ts +1 -0
package/src/pdf/pdf.service.ts
CHANGED
|
@@ -1,41 +1,49 @@
|
|
|
1
1
|
import puppeteer from "puppeteer";
|
|
2
2
|
import { v4 as uuidv4 } from "uuid";
|
|
3
|
-
import
|
|
3
|
+
import {
|
|
4
|
+
GetObjectCommand,
|
|
5
|
+
PutObjectCommand,
|
|
6
|
+
S3Client,
|
|
7
|
+
} from "@aws-sdk/client-s3";
|
|
8
|
+
import { getSignedUrl as getS3SignedUrl } from "@aws-sdk/s3-request-presigner";
|
|
4
9
|
import path from "path";
|
|
5
10
|
|
|
6
|
-
|
|
7
|
-
const s3 = new AWS.S3({
|
|
8
|
-
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
9
|
-
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
11
|
+
const s3 = new S3Client({
|
|
10
12
|
region: process.env.AWS_REGION,
|
|
13
|
+
credentials:
|
|
14
|
+
process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY
|
|
15
|
+
? {
|
|
16
|
+
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
17
|
+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
18
|
+
}
|
|
19
|
+
: undefined,
|
|
11
20
|
});
|
|
12
21
|
|
|
13
22
|
// Function to upload a file to S3
|
|
14
23
|
const uploadBuffer = async (
|
|
15
24
|
buffer: Buffer,
|
|
16
25
|
fileName: string,
|
|
17
|
-
): Promise<
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const data = await s3.upload(params).promise();
|
|
27
|
-
return data.Location;
|
|
26
|
+
): Promise<void> => {
|
|
27
|
+
await s3.send(
|
|
28
|
+
new PutObjectCommand({
|
|
29
|
+
Bucket: process.env.AWS_S3_BUCKET_NAME!,
|
|
30
|
+
Key: fileName,
|
|
31
|
+
Body: buffer,
|
|
32
|
+
ContentType: "application/pdf",
|
|
33
|
+
}),
|
|
34
|
+
);
|
|
28
35
|
};
|
|
29
36
|
|
|
30
37
|
// Generate a signed URL
|
|
31
|
-
const generateSignedUrl = (fileName: string): string => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
const generateSignedUrl = async (fileName: string): Promise<string> => {
|
|
39
|
+
return getS3SignedUrl(
|
|
40
|
+
s3,
|
|
41
|
+
new GetObjectCommand({
|
|
42
|
+
Bucket: process.env.AWS_S3_BUCKET_NAME!,
|
|
43
|
+
Key: fileName,
|
|
44
|
+
}),
|
|
45
|
+
{ expiresIn: 60 * 60 },
|
|
46
|
+
);
|
|
39
47
|
};
|
|
40
48
|
|
|
41
49
|
interface GeneratePdfOptions {
|
|
@@ -79,15 +87,12 @@ const generatePdfFromUrl = async ({
|
|
|
79
87
|
|
|
80
88
|
await browser.close();
|
|
81
89
|
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
`download-${uuidv4()}.pdf`,
|
|
85
|
-
);
|
|
90
|
+
const fileName = `download-${uuidv4()}.pdf`;
|
|
91
|
+
await uploadBuffer(Buffer.from(pdf), fileName);
|
|
86
92
|
|
|
87
|
-
console.log(`File uploaded successfully. File
|
|
93
|
+
console.log(`File uploaded successfully. File Name: ${fileName}`);
|
|
88
94
|
|
|
89
|
-
const
|
|
90
|
-
const signedUrl = generateSignedUrl(fileName);
|
|
95
|
+
const signedUrl = await generateSignedUrl(path.basename(fileName));
|
|
91
96
|
console.log(`Signed URL: ${signedUrl}`);
|
|
92
97
|
|
|
93
98
|
return signedUrl;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { z } from
|
|
2
|
-
import { extendZodWithOpenApi } from
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { extendZodWithOpenApi } from "@asteasolutions/zod-to-openapi";
|
|
3
3
|
extendZodWithOpenApi(z);
|
|
4
4
|
|
|
5
5
|
export const createUserResponseSchema = z.object({
|
|
@@ -13,7 +13,7 @@ export const getUsersResponseSchema = z.array(
|
|
|
13
13
|
id: z.string(),
|
|
14
14
|
name: z.string(),
|
|
15
15
|
email: z.string(),
|
|
16
|
-
})
|
|
16
|
+
}),
|
|
17
17
|
);
|
|
18
18
|
|
|
19
19
|
export const updateUserSchema = z.object({
|
|
@@ -30,50 +30,3 @@ export const updateUserResponseSchema = z.object({
|
|
|
30
30
|
export const deleteUserResponseSchema = z.object({
|
|
31
31
|
success: z.boolean(),
|
|
32
32
|
});
|
|
33
|
-
|
|
34
|
-
export const updateTimesByIdResponseSchema = z
|
|
35
|
-
.array(
|
|
36
|
-
z.object({
|
|
37
|
-
rrule: z
|
|
38
|
-
.object({
|
|
39
|
-
freq: z.string().optional().openapi({ example: 'DAILY', description: 'Recurrence frequency' }),
|
|
40
|
-
byweekday: z
|
|
41
|
-
.array(z.number())
|
|
42
|
-
.openapi({ example: [0, 1, 2, 6, 3], description: 'Days of week to repeat (0=Sunday)' }),
|
|
43
|
-
exclude: z.array(z.string()).openapi({ example: ['2024-03-28T10:45:00.000Z'], description: 'Dates to skip' }),
|
|
44
|
-
})
|
|
45
|
-
.openapi({ description: 'Recurrence rule object' }),
|
|
46
|
-
medication: z.string().optional().openapi({ example: '6152c5f3902e7f91374d9f75', description: 'Medication ObjectId' }),
|
|
47
|
-
patient: z.string().openapi({ example: '614fb1d709dd9f6de85d6374', description: 'Patient ObjectId' }),
|
|
48
|
-
date: z.string().openapi({ example: '2024-03-25T00:30:00.000Z', description: 'Scheduled date/time (ISO)' }),
|
|
49
|
-
timeCategory: z.string().openapi({ example: 'noon', description: 'Time category (e.g. morning, noon)' }),
|
|
50
|
-
amount: z.number().openapi({ example: 1, description: 'Dosage amount' }),
|
|
51
|
-
emptyStomach: z.boolean().openapi({ example: false, description: 'Whether to take on empty stomach' }),
|
|
52
|
-
instruction: z.string().optional().openapi({ example: '', description: 'Additional instructions' }),
|
|
53
|
-
unit: z.string().optional().openapi({ example: 'St', description: 'Dosage unit' }),
|
|
54
|
-
bake: z.boolean().openapi({ example: false, description: 'Baking flag (if applicable)' }),
|
|
55
|
-
id: z.string().openapi({ example: '660079fd11fdc2dd935e43af', description: 'Entry identifier' }),
|
|
56
|
-
})
|
|
57
|
-
)
|
|
58
|
-
.openapi({
|
|
59
|
-
example: [
|
|
60
|
-
{
|
|
61
|
-
rrule: {
|
|
62
|
-
freq: 'DAILY',
|
|
63
|
-
byweekday: [0, 1, 2, 6, 3],
|
|
64
|
-
exclude: ['2024-03-28T10:45:00.000Z'],
|
|
65
|
-
},
|
|
66
|
-
patient: '614fb1d709dd9f6de85d6374',
|
|
67
|
-
date: '2024-03-25T00:30:00.000Z',
|
|
68
|
-
timeCategory: 'noon',
|
|
69
|
-
amount: 1,
|
|
70
|
-
emptyStomach: false,
|
|
71
|
-
instruction: '',
|
|
72
|
-
unit: 'St',
|
|
73
|
-
bake: false,
|
|
74
|
-
id: '660079fd11fdc2dd935e43af',
|
|
75
|
-
},
|
|
76
|
-
// ...other items
|
|
77
|
-
],
|
|
78
|
-
description: 'Array of updated time entries by ID',
|
|
79
|
-
});
|