@amohamud23/notihub 1.1.19 → 1.1.20
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/index.cjs +20 -5
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +20 -5
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -267,15 +267,30 @@ var User = class _User {
|
|
|
267
267
|
* @returns A promise that resolves to the updated user object.
|
|
268
268
|
*/
|
|
269
269
|
static async updateUser(id, user) {
|
|
270
|
+
const updateFields = Object.keys(user);
|
|
271
|
+
if (updateFields.length === 0) {
|
|
272
|
+
throw new Error("No fields provided to update.");
|
|
273
|
+
}
|
|
274
|
+
const UpdateExpression = `SET ${updateFields.map((field, idx) => `#field${idx} = :value${idx}`).join(", ")}`;
|
|
275
|
+
const ExpressionAttributeNames = updateFields.reduce((acc, field, idx) => {
|
|
276
|
+
acc[`#field${idx}`] = field;
|
|
277
|
+
return acc;
|
|
278
|
+
}, {});
|
|
279
|
+
const ExpressionAttributeValues = updateFields.reduce((acc, field, idx) => {
|
|
280
|
+
acc[`:value${idx}`] = user[field];
|
|
281
|
+
return acc;
|
|
282
|
+
}, {});
|
|
270
283
|
const command = new import_lib_dynamodb2.UpdateCommand({
|
|
271
284
|
TableName: _User.TABLE_NAME,
|
|
272
|
-
Key: {
|
|
273
|
-
|
|
274
|
-
|
|
285
|
+
Key: { id },
|
|
286
|
+
UpdateExpression,
|
|
287
|
+
ExpressionAttributeNames,
|
|
288
|
+
ExpressionAttributeValues,
|
|
289
|
+
ReturnValues: "ALL_NEW"
|
|
275
290
|
});
|
|
276
291
|
try {
|
|
277
|
-
await ddbDocClient.send(command);
|
|
278
|
-
return
|
|
292
|
+
const result = await ddbDocClient.send(command);
|
|
293
|
+
return result.Attributes;
|
|
279
294
|
} catch (error) {
|
|
280
295
|
console.error("Error updating user: ", error);
|
|
281
296
|
throw new Error("Could not update user");
|
package/dist/index.d.cts
CHANGED
|
@@ -287,7 +287,7 @@ declare class User {
|
|
|
287
287
|
* @param user - The user object to update.
|
|
288
288
|
* @returns A promise that resolves to the updated user object.
|
|
289
289
|
*/
|
|
290
|
-
static updateUser(id: string, user: INotiHubUser): Promise<INotiHubUser>;
|
|
290
|
+
static updateUser(id: string, user: Partial<INotiHubUser>): Promise<INotiHubUser>;
|
|
291
291
|
/**
|
|
292
292
|
* Deletes a user by their ID.
|
|
293
293
|
* @param id - The ID of the user to delete.
|
package/dist/index.d.ts
CHANGED
|
@@ -287,7 +287,7 @@ declare class User {
|
|
|
287
287
|
* @param user - The user object to update.
|
|
288
288
|
* @returns A promise that resolves to the updated user object.
|
|
289
289
|
*/
|
|
290
|
-
static updateUser(id: string, user: INotiHubUser): Promise<INotiHubUser>;
|
|
290
|
+
static updateUser(id: string, user: Partial<INotiHubUser>): Promise<INotiHubUser>;
|
|
291
291
|
/**
|
|
292
292
|
* Deletes a user by their ID.
|
|
293
293
|
* @param id - The ID of the user to delete.
|
package/dist/index.js
CHANGED
|
@@ -234,15 +234,30 @@ var User = class _User {
|
|
|
234
234
|
* @returns A promise that resolves to the updated user object.
|
|
235
235
|
*/
|
|
236
236
|
static async updateUser(id, user) {
|
|
237
|
+
const updateFields = Object.keys(user);
|
|
238
|
+
if (updateFields.length === 0) {
|
|
239
|
+
throw new Error("No fields provided to update.");
|
|
240
|
+
}
|
|
241
|
+
const UpdateExpression = `SET ${updateFields.map((field, idx) => `#field${idx} = :value${idx}`).join(", ")}`;
|
|
242
|
+
const ExpressionAttributeNames = updateFields.reduce((acc, field, idx) => {
|
|
243
|
+
acc[`#field${idx}`] = field;
|
|
244
|
+
return acc;
|
|
245
|
+
}, {});
|
|
246
|
+
const ExpressionAttributeValues = updateFields.reduce((acc, field, idx) => {
|
|
247
|
+
acc[`:value${idx}`] = user[field];
|
|
248
|
+
return acc;
|
|
249
|
+
}, {});
|
|
237
250
|
const command = new UpdateCommand({
|
|
238
251
|
TableName: _User.TABLE_NAME,
|
|
239
|
-
Key: {
|
|
240
|
-
|
|
241
|
-
|
|
252
|
+
Key: { id },
|
|
253
|
+
UpdateExpression,
|
|
254
|
+
ExpressionAttributeNames,
|
|
255
|
+
ExpressionAttributeValues,
|
|
256
|
+
ReturnValues: "ALL_NEW"
|
|
242
257
|
});
|
|
243
258
|
try {
|
|
244
|
-
await ddbDocClient.send(command);
|
|
245
|
-
return
|
|
259
|
+
const result = await ddbDocClient.send(command);
|
|
260
|
+
return result.Attributes;
|
|
246
261
|
} catch (error) {
|
|
247
262
|
console.error("Error updating user: ", error);
|
|
248
263
|
throw new Error("Could not update user");
|