pangea-server 3.3.157 → 3.3.159

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.
@@ -120,10 +120,7 @@ class Db {
120
120
  const searchWords = search.split(/\s+/).filter(Boolean);
121
121
  searchWhere = {
122
122
  [_1.Ops.and]: searchWords.map((word) => ({
123
- [_1.Ops.or]: searchFields.map((field) => {
124
- const finalField = field.includes('.') ? `$${field}$` : field;
125
- return { [finalField]: { [_1.Ops.like]: `%${word}%` } };
126
- }),
123
+ [_1.Ops.or]: searchFields.map((field) => getSearchFieldCondition(model, field, word)),
127
124
  })),
128
125
  };
129
126
  }
@@ -231,6 +228,32 @@ function formatField(modelName, field) {
231
228
  }
232
229
  return `${modelName}.${(0, pangea_helpers_1.camelToSnake)(field)}`;
233
230
  }
231
+ function getSearchCorrelation(association, parentAlias, childAlias) {
232
+ if (association.associationType === 'BelongsTo') {
233
+ return `${childAlias}.\`${association.targetKeyField || 'id'}\` = ${parentAlias}.\`${association.identifierField}\``;
234
+ }
235
+ return `${childAlias}.\`${association.identifierField}\` = ${parentAlias}.\`${association.sourceKeyField || 'id'}\``;
236
+ }
237
+ function buildSearchExists(parentModel, parentAlias, segments, escapedWord, depth) {
238
+ const [relName, ...rest] = segments;
239
+ const association = parentModel.associations[relName];
240
+ const childModel = association.target;
241
+ const childAlias = `\`__search_${relName}_${depth}\``;
242
+ const conditions = [getSearchCorrelation(association, parentAlias, childAlias)];
243
+ if (parentModel.Relations[relName]?.paranoid)
244
+ conditions.push(`${childAlias}.\`deleted_at\` IS NULL`);
245
+ if (rest.length === 1)
246
+ conditions.push(`${childAlias}.\`${(0, pangea_helpers_1.camelToSnake)(rest[0])}\` LIKE ${escapedWord}`);
247
+ else
248
+ conditions.push(buildSearchExists(childModel, childAlias, rest, escapedWord, depth + 1));
249
+ return `EXISTS (SELECT 1 FROM \`${childModel.tableName}\` AS ${childAlias} WHERE ${conditions.join(' AND ')})`;
250
+ }
251
+ function getSearchFieldCondition(model, field, word) {
252
+ if (!field.includes('.'))
253
+ return { [field]: { [_1.Ops.like]: `%${word}%` } };
254
+ const escapedWord = (0, db_client_1.getDbClient)().escape(`%${word}%`);
255
+ return (0, sequelize_1.literal)(buildSearchExists(model, `\`${model.name}\``, field.split('.'), escapedWord, 0));
256
+ }
234
257
  function getFinalAttributes(model, attributes) {
235
258
  if (!attributes)
236
259
  return;
@@ -251,7 +274,7 @@ function convertWhereKeys(obj) {
251
274
  !(obj instanceof RegExp) &&
252
275
  !(obj instanceof Map) &&
253
276
  !(obj instanceof Set) &&
254
- !(obj instanceof utils_1.Where) &&
277
+ !(obj instanceof utils_1.SequelizeMethod) &&
255
278
  !(typeof obj === 'function')) {
256
279
  const newObj = {};
257
280
  for (const key of Reflect.ownKeys(obj)) {
@@ -39,48 +39,66 @@ class Google {
39
39
  return (response.data.items || []).map(convertEvent);
40
40
  }
41
41
  async createEvent(options) {
42
- const response = await this.__calendar.events.insert({
43
- calendarId: 'primary',
44
- requestBody: {
45
- summary: options.title,
46
- description: options.description,
47
- location: options.location,
48
- start: { dateTime: options.start.toISOString() },
49
- end: { dateTime: options.end.toISOString() },
50
- attendees: options.attendees?.map((email) => ({ email })),
51
- conferenceData: options.meet
52
- ? {
53
- createRequest: {
54
- requestId: `meet-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`,
55
- conferenceSolutionKey: { type: 'hangoutsMeet' },
56
- },
57
- }
58
- : undefined,
59
- },
60
- conferenceDataVersion: options.meet ? 1 : undefined,
61
- });
62
- return convertEvent(response.data);
42
+ try {
43
+ const response = await this.__calendar.events.insert({
44
+ calendarId: 'primary',
45
+ requestBody: {
46
+ summary: options.title,
47
+ description: options.description,
48
+ location: options.location,
49
+ start: { dateTime: options.start.toISOString() },
50
+ end: { dateTime: options.end.toISOString() },
51
+ attendees: options.attendees?.map((email) => ({ email })),
52
+ conferenceData: options.meet
53
+ ? {
54
+ createRequest: {
55
+ requestId: `meet-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`,
56
+ conferenceSolutionKey: { type: 'hangoutsMeet' },
57
+ },
58
+ }
59
+ : undefined,
60
+ },
61
+ conferenceDataVersion: options.meet ? 1 : undefined,
62
+ });
63
+ return convertEvent(response.data);
64
+ }
65
+ catch (err) {
66
+ (0, helpers_1.printDanger)('google', err);
67
+ throw err;
68
+ }
63
69
  }
64
70
  async updateEvent(eventId, options) {
65
- const { title, description, location, start, end, attendees } = options;
66
- const requestBody = {};
67
- if (title !== undefined)
68
- requestBody.summary = title;
69
- if (description !== undefined)
70
- requestBody.description = description;
71
- if (location !== undefined)
72
- requestBody.location = location;
73
- if (start !== undefined)
74
- requestBody.start = { dateTime: start.toISOString() };
75
- if (end !== undefined)
76
- requestBody.end = { dateTime: end.toISOString() };
77
- if (attendees !== undefined)
78
- requestBody.attendees = attendees.map((email) => ({ email }));
79
- const response = await this.__calendar.events.patch({ calendarId: 'primary', eventId, requestBody });
80
- return convertEvent(response.data);
71
+ try {
72
+ const { title, description, location, start, end, attendees } = options;
73
+ const requestBody = {};
74
+ if (title !== undefined)
75
+ requestBody.summary = title;
76
+ if (description !== undefined)
77
+ requestBody.description = description;
78
+ if (location !== undefined)
79
+ requestBody.location = location;
80
+ if (start !== undefined)
81
+ requestBody.start = { dateTime: start.toISOString() };
82
+ if (end !== undefined)
83
+ requestBody.end = { dateTime: end.toISOString() };
84
+ if (attendees !== undefined)
85
+ requestBody.attendees = attendees.map((email) => ({ email }));
86
+ const response = await this.__calendar.events.patch({ calendarId: 'primary', eventId, requestBody });
87
+ return convertEvent(response.data);
88
+ }
89
+ catch (err) {
90
+ (0, helpers_1.printDanger)('google', err);
91
+ throw err;
92
+ }
81
93
  }
82
94
  async deleteEvent(eventId) {
83
- await this.__calendar.events.delete({ calendarId: 'primary', eventId });
95
+ try {
96
+ await this.__calendar.events.delete({ calendarId: 'primary', eventId });
97
+ }
98
+ catch (err) {
99
+ (0, helpers_1.printDanger)('google', err);
100
+ throw err;
101
+ }
84
102
  }
85
103
  }
86
104
  exports.Google = Google;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pangea-server",
3
3
  "description": "",
4
- "version": "3.3.157",
4
+ "version": "3.3.159",
5
5
  "engines": {
6
6
  "node": "22.14.0"
7
7
  },