@internetderdinge/api 1.224.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/.github/copilot-instructions.md +77 -0
- package/CHANGELOG.md +11 -0
- package/README.md +52 -0
- package/package.json +112 -0
- package/src/accounts/accounts.controller.ts +166 -0
- package/src/accounts/accounts.route.ts +107 -0
- package/src/accounts/accounts.schemas.ts +16 -0
- package/src/accounts/accounts.service.ts +85 -0
- package/src/accounts/accounts.validation.ts +118 -0
- package/src/accounts/auth0.service.ts +226 -0
- package/src/config/config.ts +49 -0
- package/src/config/logger.ts +33 -0
- package/src/config/morgan.ts +22 -0
- package/src/config/passport.cjs +30 -0
- package/src/config/roles.ts +13 -0
- package/src/config/tokens.cjs +10 -0
- package/src/devices/devices.controller.ts +276 -0
- package/src/devices/devices.model.ts +126 -0
- package/src/devices/devices.route.ts +198 -0
- package/src/devices/devices.schemas.ts +94 -0
- package/src/devices/devices.service.ts +320 -0
- package/src/devices/devices.validation.ts +221 -0
- package/src/devicesNotifications/devicesNotifications.controller.ts +72 -0
- package/src/devicesNotifications/devicesNotifications.model.ts +67 -0
- package/src/devicesNotifications/devicesNotifications.route.ts +150 -0
- package/src/devicesNotifications/devicesNotifications.schemas.ts +11 -0
- package/src/devicesNotifications/devicesNotifications.service.ts +222 -0
- package/src/devicesNotifications/devicesNotifications.validation.ts +56 -0
- package/src/email/email.service.ts +609 -0
- package/src/files/upload.service.ts +145 -0
- package/src/i18n/i18n.ts +51 -0
- package/src/i18n/saveMissingLocalJsonBackend.ts +92 -0
- package/src/index.ts +7 -0
- package/src/iotdevice/iotdevice.controller.ts +136 -0
- package/src/iotdevice/iotdevice.model.ts +32 -0
- package/src/iotdevice/iotdevice.route.ts +181 -0
- package/src/iotdevice/iotdevice.schemas.ts +79 -0
- package/src/iotdevice/iotdevice.service.ts +732 -0
- package/src/iotdevice/iotdevice.validation.ts +61 -0
- package/src/middlewares/auth.ts +110 -0
- package/src/middlewares/checkJwt.cjs +19 -0
- package/src/middlewares/error.js.legacy +44 -0
- package/src/middlewares/error.ts +41 -0
- package/src/middlewares/mongooseValidations/ensureSameOrganization.ts +15 -0
- package/src/middlewares/rateLimiter.ts +10 -0
- package/src/middlewares/validate.ts +25 -0
- package/src/middlewares/validateAction.ts +41 -0
- package/src/middlewares/validateAdmin.ts +21 -0
- package/src/middlewares/validateAi.ts +24 -0
- package/src/middlewares/validateCurrentAuthUser.ts +23 -0
- package/src/middlewares/validateCurrentUser.ts +35 -0
- package/src/middlewares/validateDevice.ts +191 -0
- package/src/middlewares/validateDeviceUserOrganization.ts +54 -0
- package/src/middlewares/validateOrganization.ts +109 -0
- package/src/middlewares/validateQuerySearchUserAndOrganization.ts +75 -0
- package/src/middlewares/validateTokens.ts +36 -0
- package/src/middlewares/validateUser.ts +75 -0
- package/src/middlewares/validateZod.ts +54 -0
- package/src/models/plugins/index.ts +7 -0
- package/src/models/plugins/paginate.plugin.ts +145 -0
- package/src/models/plugins/paginateNew.plugin.ts +206 -0
- package/src/models/plugins/simplePopulate.ts +12 -0
- package/src/models/plugins/toJSON.plugin.ts +51 -0
- package/src/organizations/organizations.controller.ts +101 -0
- package/src/organizations/organizations.model.ts +62 -0
- package/src/organizations/organizations.route.ts +119 -0
- package/src/organizations/organizations.schemas.ts +8 -0
- package/src/organizations/organizations.service.ts +85 -0
- package/src/organizations/organizations.validation.ts +76 -0
- package/src/pdf/pdf.controller.ts +18 -0
- package/src/pdf/pdf.route.ts +28 -0
- package/src/pdf/pdf.schemas.ts +7 -0
- package/src/pdf/pdf.service.ts +89 -0
- package/src/pdf/pdf.validation.ts +30 -0
- package/src/tokens/tokens.controller.ts +81 -0
- package/src/tokens/tokens.model.ts +24 -0
- package/src/tokens/tokens.route.ts +66 -0
- package/src/tokens/tokens.schemas.ts +15 -0
- package/src/tokens/tokens.service.ts +46 -0
- package/src/tokens/tokens.validation.ts +13 -0
- package/src/types/routeSpec.ts +1 -0
- package/src/users/users.controller.ts +234 -0
- package/src/users/users.model.ts +89 -0
- package/src/users/users.route.ts +171 -0
- package/src/users/users.schemas.ts +79 -0
- package/src/users/users.service.ts +393 -0
- package/src/users/users.validation.ts +166 -0
- package/src/utils/ApiError.ts +18 -0
- package/src/utils/buildRouterAndDocs.ts +85 -0
- package/src/utils/catchAsync.ts +9 -0
- package/src/utils/comparePapers.service.ts +48 -0
- package/src/utils/filterOptions.ts +37 -0
- package/src/utils/medicationName.ts +12 -0
- package/src/utils/pick.ts +16 -0
- package/src/utils/registerOpenApi.ts +32 -0
- package/src/utils/urlUtils.ts +14 -0
- package/src/utils/userName.ts +27 -0
- package/src/utils/zValidations.ts +89 -0
- package/src/validations/auth.validation.cjs +60 -0
- package/src/validations/custom.validation.ts +26 -0
- package/src/validations/index.cjs +2 -0
- package/tsconfig.json +22 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { Router } from 'express';
|
|
2
|
+
import buildRouterAndDocs from '../../src/utils/buildRouterAndDocs';
|
|
3
|
+
import type { RouteSpec } from '../types/routeSpec';
|
|
4
|
+
|
|
5
|
+
import auth from '../../src/middlewares/auth';
|
|
6
|
+
import validateCurrentUser from '../../src/middlewares/validateCurrentUser';
|
|
7
|
+
import { validateAdmin } from '../../src/middlewares/validateAdmin';
|
|
8
|
+
import validateCurrentAuthUser from '../../src/middlewares/validateCurrentAuthUser';
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
createEntrySchema,
|
|
12
|
+
queryNotificationsByUserSchema,
|
|
13
|
+
setDeviceTokenSchema,
|
|
14
|
+
removeDeviceTokenSchema,
|
|
15
|
+
cleanupSchema,
|
|
16
|
+
getEntrySchema,
|
|
17
|
+
updateEntrySchema,
|
|
18
|
+
deleteEntrySchema,
|
|
19
|
+
} from './devicesNotifications.validation';
|
|
20
|
+
|
|
21
|
+
import { deviceNotificationResponseSchema } from './devicesNotifications.schemas';
|
|
22
|
+
|
|
23
|
+
import {
|
|
24
|
+
createEntry,
|
|
25
|
+
queryNotificationsByUser,
|
|
26
|
+
setDeviceToken,
|
|
27
|
+
removeDeviceToken,
|
|
28
|
+
cleanup,
|
|
29
|
+
getEntry,
|
|
30
|
+
updateEntry,
|
|
31
|
+
deleteEntry,
|
|
32
|
+
} from './devicesNotifications.controller';
|
|
33
|
+
|
|
34
|
+
export const devicesNotificationsRouteSpecs: RouteSpec[] = [
|
|
35
|
+
{
|
|
36
|
+
method: 'post',
|
|
37
|
+
path: '/',
|
|
38
|
+
validate: [auth('manageUsers')],
|
|
39
|
+
requestSchema: createEntrySchema,
|
|
40
|
+
responseSchema: deviceNotificationResponseSchema,
|
|
41
|
+
privateDocs: true,
|
|
42
|
+
handler: createEntry,
|
|
43
|
+
summary: 'Create a new device-notification entry',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
method: 'get',
|
|
47
|
+
path: '/',
|
|
48
|
+
validate: [auth('getUsers')],
|
|
49
|
+
requestSchema: queryNotificationsByUserSchema,
|
|
50
|
+
responseSchema: deviceNotificationResponseSchema.array(),
|
|
51
|
+
privateDocs: true,
|
|
52
|
+
handler: queryNotificationsByUser,
|
|
53
|
+
summary: 'Query notifications by user',
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
method: 'post',
|
|
57
|
+
path: '/setDeviceToken',
|
|
58
|
+
validate: [auth('manageUsers')],
|
|
59
|
+
requestSchema: setDeviceTokenSchema,
|
|
60
|
+
responseSchema: deviceNotificationResponseSchema,
|
|
61
|
+
privateDocs: true,
|
|
62
|
+
handler: setDeviceToken,
|
|
63
|
+
summary: 'Associate a device token with a user',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
method: 'get',
|
|
67
|
+
path: '/setDeviceToken',
|
|
68
|
+
validate: [auth('getUsers'), validateCurrentUser],
|
|
69
|
+
requestSchema: queryNotificationsByUserSchema,
|
|
70
|
+
responseSchema: deviceNotificationResponseSchema.array(),
|
|
71
|
+
privateDocs: true,
|
|
72
|
+
handler: queryNotificationsByUser,
|
|
73
|
+
summary: 'Query notifications by user (after setting token)',
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
method: 'post',
|
|
77
|
+
path: '/removeDeviceToken',
|
|
78
|
+
validate: [auth('manageUsers')],
|
|
79
|
+
requestSchema: removeDeviceTokenSchema,
|
|
80
|
+
responseSchema: deviceNotificationResponseSchema,
|
|
81
|
+
privateDocs: true,
|
|
82
|
+
handler: removeDeviceToken,
|
|
83
|
+
summary: 'Remove a device token from a user',
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
method: 'get',
|
|
87
|
+
path: '/removeDeviceToken',
|
|
88
|
+
validate: [auth('getUsers'), validateCurrentUser],
|
|
89
|
+
requestSchema: queryNotificationsByUserSchema,
|
|
90
|
+
responseSchema: deviceNotificationResponseSchema.array(),
|
|
91
|
+
privateDocs: true,
|
|
92
|
+
handler: queryNotificationsByUser,
|
|
93
|
+
summary: 'Query notifications by user (after removing token)',
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
method: 'get',
|
|
97
|
+
path: '/cleanup',
|
|
98
|
+
validate: [auth('manageUsers'), validateAdmin],
|
|
99
|
+
requestSchema: cleanupSchema,
|
|
100
|
+
responseSchema: deviceNotificationResponseSchema.array(),
|
|
101
|
+
privateDocs: true,
|
|
102
|
+
handler: cleanup,
|
|
103
|
+
summary: 'Cleanup old device-notification entries',
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
method: 'get',
|
|
107
|
+
path: '/cleanup',
|
|
108
|
+
validate: [auth('getUsers'), validateCurrentUser, validateAdmin],
|
|
109
|
+
requestSchema: queryNotificationsByUserSchema,
|
|
110
|
+
responseSchema: deviceNotificationResponseSchema.array(),
|
|
111
|
+
privateDocs: true,
|
|
112
|
+
handler: queryNotificationsByUser,
|
|
113
|
+
summary: 'Query notifications by user (after cleanup)',
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
method: 'get',
|
|
117
|
+
path: '/:notificationId',
|
|
118
|
+
validate: [auth('getUsers')],
|
|
119
|
+
requestSchema: getEntrySchema,
|
|
120
|
+
responseSchema: deviceNotificationResponseSchema,
|
|
121
|
+
privateDocs: true,
|
|
122
|
+
handler: getEntry,
|
|
123
|
+
summary: 'Get a device-notification by ID',
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
method: 'patch',
|
|
127
|
+
path: '/:notificationId',
|
|
128
|
+
validate: [auth('manageUsers'), validateCurrentAuthUser],
|
|
129
|
+
requestSchema: updateEntrySchema,
|
|
130
|
+
responseSchema: deviceNotificationResponseSchema,
|
|
131
|
+
privateDocs: true,
|
|
132
|
+
handler: updateEntry,
|
|
133
|
+
summary: 'Update a device-notification by ID',
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
method: 'delete',
|
|
137
|
+
path: '/:notificationId',
|
|
138
|
+
validate: [auth('manageUsers'), validateCurrentAuthUser],
|
|
139
|
+
requestSchema: deleteEntrySchema,
|
|
140
|
+
responseSchema: deviceNotificationResponseSchema,
|
|
141
|
+
privateDocs: true,
|
|
142
|
+
handler: deleteEntry,
|
|
143
|
+
summary: 'Delete a device-notification by ID',
|
|
144
|
+
},
|
|
145
|
+
];
|
|
146
|
+
|
|
147
|
+
const router = Router();
|
|
148
|
+
buildRouterAndDocs(router, devicesNotificationsRouteSpecs, '/devices-notifications', ['DevicesNotifications']);
|
|
149
|
+
|
|
150
|
+
export default router;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
export const deviceNotificationResponseSchema = z.object({
|
|
4
|
+
id: z.string().uuid(),
|
|
5
|
+
userId: z.string().uuid(),
|
|
6
|
+
deviceToken: z.string(),
|
|
7
|
+
// optionally include platform or other metadata:
|
|
8
|
+
platform: z.enum(['ios', 'android']).optional(),
|
|
9
|
+
createdAt: z.string().datetime(),
|
|
10
|
+
updatedAt: z.string().datetime(),
|
|
11
|
+
});
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import httpStatus from 'http-status';
|
|
2
|
+
import { SESv2Client, ListSuppressedDestinationsCommand } from '@aws-sdk/client-sesv2';
|
|
3
|
+
import DeviceNotification from './devicesNotifications.model';
|
|
4
|
+
import ApiError from '../../src/utils/ApiError';
|
|
5
|
+
import { auth0 } from '../accounts/auth0.service';
|
|
6
|
+
|
|
7
|
+
import type { Notification } from './devicesNotifications.model';
|
|
8
|
+
import type { FilterQuery, PaginateOptions, QueryResult } from 'mongoose';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Create a user
|
|
12
|
+
* @param {Object} userBody
|
|
13
|
+
* @returns {Promise<Notification>}
|
|
14
|
+
*/
|
|
15
|
+
export const createNotificationUser = async ({ user }: { user: string }): Promise<Notification> => {
|
|
16
|
+
const result = await DeviceNotification.findOne({ user });
|
|
17
|
+
if (result) throw new ApiError(httpStatus.NOT_FOUND, 'DevicesNotifications user existing');
|
|
18
|
+
const devicesNotification = await DeviceNotification.create({ user });
|
|
19
|
+
return devicesNotification;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Set the device token for a user
|
|
24
|
+
* @param {Object} userBody
|
|
25
|
+
* @returns {Promise<Notification>}
|
|
26
|
+
*/
|
|
27
|
+
export const setDeviceToken = async ({
|
|
28
|
+
user,
|
|
29
|
+
body,
|
|
30
|
+
}: {
|
|
31
|
+
user: string;
|
|
32
|
+
body: { token: string; deviceId: string; [key: string]: any };
|
|
33
|
+
}): Promise<Notification> => {
|
|
34
|
+
const { token, ...meta } = body;
|
|
35
|
+
let result = await DeviceNotification.findOne({ user });
|
|
36
|
+
if (!result) {
|
|
37
|
+
result = await createNotificationUser({ user });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
result.tokens = [...new Map(result.tokens.map((m) => [m.deviceId, m])).values()];
|
|
41
|
+
|
|
42
|
+
if (result.tokens.find((t) => t.token === token)) return result;
|
|
43
|
+
|
|
44
|
+
result.tokens = result.tokens.filter((t) => t.deviceId !== meta.deviceId);
|
|
45
|
+
result.tokens.push({ token, ...meta });
|
|
46
|
+
await result.save();
|
|
47
|
+
return result;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Remove an existing device token usually used when the user is getting logged out
|
|
52
|
+
* @param {Object} userBody
|
|
53
|
+
* @returns {Promise<Notification>}
|
|
54
|
+
*/
|
|
55
|
+
export const removeDeviceToken = async ({
|
|
56
|
+
user,
|
|
57
|
+
body: { deviceId },
|
|
58
|
+
}: {
|
|
59
|
+
user: string;
|
|
60
|
+
body: { deviceId: string };
|
|
61
|
+
}): Promise<Notification> => {
|
|
62
|
+
let result = await DeviceNotification.findOne({ user });
|
|
63
|
+
if (!result) {
|
|
64
|
+
result = await createNotificationUser({ user });
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (result.tokens.find((t) => t.deviceId === deviceId)) {
|
|
68
|
+
result.tokens = result.tokens.filter((t) => t.deviceId !== deviceId);
|
|
69
|
+
await result.save();
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/*
|
|
75
|
+
const convertAllTokens = async () => {
|
|
76
|
+
const devicesNotifications = await DeviceNotification.find();
|
|
77
|
+
|
|
78
|
+
await Promise.all(
|
|
79
|
+
devicesNotifications.map(async (user) => {
|
|
80
|
+
//const tokenListNewFiltered = user.tokens.filter((v, i, a) => a.findIndex((v2) => v2 === v) === i);
|
|
81
|
+
|
|
82
|
+
const tokenListNew = user.tokens.map((ttt) => {
|
|
83
|
+
if (typeof ttt === 'string') {
|
|
84
|
+
return { token: ttt };
|
|
85
|
+
}
|
|
86
|
+
return ttt;
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
console.log(tokenListNew);
|
|
90
|
+
|
|
91
|
+
const devicesNotification = await updateById(user.id, {
|
|
92
|
+
tokens: [],
|
|
93
|
+
});
|
|
94
|
+
})
|
|
95
|
+
);
|
|
96
|
+
};*/
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Query for users
|
|
100
|
+
* @param {Object} filter - Mongo filter
|
|
101
|
+
* @param {Object} options - Query options
|
|
102
|
+
* @param {string} [options.sortBy] - Sort option in the format: sortField:(desc|asc)
|
|
103
|
+
* @param {number} [options.limit] - Maximum number of results per page (default = 10)
|
|
104
|
+
* @param {number} [options.page] - Current page (default = 1)
|
|
105
|
+
* @returns {Promise<QueryResult>}
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
const queryNotificationsByUser = async (filter, options) => {
|
|
109
|
+
return DeviceNotification.paginate(filter, options);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const getById = async (id) => {
|
|
113
|
+
return DeviceNotification.findById(id);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const getByUser = async (user) => {
|
|
117
|
+
return DeviceNotification.findOne({ user });
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const updateById = async (notificationId, updateBody) => {
|
|
121
|
+
const user = await getById(notificationId);
|
|
122
|
+
if (!user) {
|
|
123
|
+
throw new ApiError(httpStatus.NOT_FOUND, 'Notification not found');
|
|
124
|
+
}
|
|
125
|
+
Object.assign(user, updateBody);
|
|
126
|
+
await user.save();
|
|
127
|
+
return user;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const updateByUserId = async (user, updateBody) => {
|
|
131
|
+
const userEntryExists = await DeviceNotification.findOne({ user });
|
|
132
|
+
if (!userEntryExists) {
|
|
133
|
+
const newUser = await createNotification({ user });
|
|
134
|
+
//throw new ApiError(httpStatus.NOT_FOUND, 'DeviceNotification not found');
|
|
135
|
+
}
|
|
136
|
+
const userEntry = await DeviceNotification.findOne({ user });
|
|
137
|
+
Object.assign(userEntry, updateBody);
|
|
138
|
+
await userEntry.save();
|
|
139
|
+
|
|
140
|
+
return userEntry;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Delete user by id
|
|
145
|
+
* @param {ObjectId} userId
|
|
146
|
+
* @returns {Promise<Notification>}
|
|
147
|
+
*/
|
|
148
|
+
const deleteById = async (userId) => {
|
|
149
|
+
const user = await getById(userId);
|
|
150
|
+
if (!user) {
|
|
151
|
+
throw new ApiError(httpStatus.NOT_FOUND, 'Notification not found');
|
|
152
|
+
}
|
|
153
|
+
await user.deleteOne();
|
|
154
|
+
return user;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Delete user by id
|
|
159
|
+
* @param {ObjectId} userId
|
|
160
|
+
* @returns {Promise<Notification>}
|
|
161
|
+
*/
|
|
162
|
+
const cleanup = async () => {
|
|
163
|
+
const deviceNotifications = await DeviceNotification.find();
|
|
164
|
+
|
|
165
|
+
const auth0Users = await auth0.getUsers();
|
|
166
|
+
|
|
167
|
+
const sesV2 = new SESv2Client({ region: 'eu-central-1' });
|
|
168
|
+
const input = {
|
|
169
|
+
Reasons: ['BOUNCE' || 'COMPLAINT'],
|
|
170
|
+
PageSize: 300,
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const command = new ListSuppressedDestinationsCommand(input);
|
|
174
|
+
const suppressedDestinations = await sesV2.send(command);
|
|
175
|
+
|
|
176
|
+
const suppressedEmailList = suppressedDestinations.SuppressedDestinationSummaries.map((a) => a.EmailAddress);
|
|
177
|
+
const suppressedEmailAuth0Users = auth0Users.filter((a) => suppressedEmailList.includes(a.email));
|
|
178
|
+
await Promise.all(
|
|
179
|
+
suppressedEmailAuth0Users.map(async (a) => {
|
|
180
|
+
updateByUserId(a.user_id, { bounceEmail: a.email });
|
|
181
|
+
}),
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
return { suppressedEmailList, suppressedEmailAuth0Users };
|
|
185
|
+
|
|
186
|
+
/* deviceNotifications.map((d) => {
|
|
187
|
+
d.tokens.forEach((token) => {
|
|
188
|
+
|
|
189
|
+
if token
|
|
190
|
+
});
|
|
191
|
+
});*/
|
|
192
|
+
|
|
193
|
+
//const resultJson = result.toJSON();
|
|
194
|
+
//const resultsFiltered = result.filter((e) => e.patientData === null);
|
|
195
|
+
|
|
196
|
+
//const idList = resultsFiltered.map((e) => e._id);
|
|
197
|
+
|
|
198
|
+
// const deleted = await calendarsService.deleteMany(idList);
|
|
199
|
+
|
|
200
|
+
return { deviceNotifications, auth0Users, response };
|
|
201
|
+
|
|
202
|
+
/* res.send({
|
|
203
|
+
deleted,
|
|
204
|
+
idList,
|
|
205
|
+
resultsFiltered,
|
|
206
|
+
resultsFilteredLength: resultsFiltered.length,
|
|
207
|
+
resultLength: result.length,
|
|
208
|
+
});*/
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
export default {
|
|
212
|
+
createNotificationUser,
|
|
213
|
+
getById,
|
|
214
|
+
cleanup,
|
|
215
|
+
queryNotificationsByUser,
|
|
216
|
+
setDeviceToken,
|
|
217
|
+
removeDeviceToken,
|
|
218
|
+
getByUser,
|
|
219
|
+
updateById,
|
|
220
|
+
updateByUserId,
|
|
221
|
+
deleteById,
|
|
222
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { objectId } from '../../src/validations/custom.validation';
|
|
4
|
+
import { zPagination, zGet, zObjectId, zPatchBody, zUpdate, zDelete } from '../../src/utils/zValidations';
|
|
5
|
+
|
|
6
|
+
extendZodWithOpenApi(z);
|
|
7
|
+
|
|
8
|
+
export const createEntrySchema = {
|
|
9
|
+
body: z.object({
|
|
10
|
+
token: z.string().optional().openapi({ description: 'Push token' }),
|
|
11
|
+
}),
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const setDeviceTokenSchema = {
|
|
15
|
+
body: z.object({
|
|
16
|
+
token: z.string().openapi({ description: 'Device token' }),
|
|
17
|
+
deviceId: z.string().openapi({ description: 'Device identifier' }),
|
|
18
|
+
plattform: z.string().openapi({ description: 'Platform name' }),
|
|
19
|
+
app: z.string().optional().openapi({ description: 'Application name' }),
|
|
20
|
+
}),
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const removeDeviceTokenSchema = {
|
|
24
|
+
body: z.object({
|
|
25
|
+
deviceId: z.string().openapi({ description: 'Device identifier' }),
|
|
26
|
+
plattform: z.string().optional().openapi({ description: 'Platform name' }),
|
|
27
|
+
app: z.string().optional().openapi({ description: 'Application name' }),
|
|
28
|
+
token: z.string().optional().openapi({ description: 'Push token' }),
|
|
29
|
+
}),
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const getUsersSchema = {
|
|
33
|
+
...zPagination,
|
|
34
|
+
query: zPagination.query.extend({
|
|
35
|
+
name: z.string().optional().openapi({ description: 'Filter by user name' }),
|
|
36
|
+
role: z.string().optional().openapi({ description: 'Filter by role' }),
|
|
37
|
+
sortBy: z.string().optional().openapi({ description: 'Sort order' }),
|
|
38
|
+
}),
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const getEntrySchema = zGet('notificationId');
|
|
42
|
+
|
|
43
|
+
export const updateEntrySchema = {
|
|
44
|
+
...zUpdate('notificationId'),
|
|
45
|
+
body: zPatchBody({
|
|
46
|
+
name: z.string().optional().openapi({ description: 'Notification name' }),
|
|
47
|
+
conditions: z.array(z.any()).optional().openapi({ description: 'Conditions array' }),
|
|
48
|
+
actions: z.array(z.any()).optional().openapi({ description: 'Actions array' }),
|
|
49
|
+
organization: z.string().optional().openapi({ description: 'Organization ID' }),
|
|
50
|
+
}),
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const deleteEntrySchema = zDelete('notificationId');
|
|
54
|
+
|
|
55
|
+
export const cleanupSchema = {};
|
|
56
|
+
export const queryNotificationsByUserSchema = {};
|