@shisyamo4131/air-guard-v2-schemas 2.3.8-dev.0 → 2.3.8-dev.1
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 +1 -1
- package/src/User.js +33 -0
package/package.json
CHANGED
package/src/User.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* @version 1.1.0
|
|
4
4
|
* @author shisyamo4131
|
|
5
5
|
* @update 2025-12-25 Added `tagSize` property.
|
|
6
|
+
* Added `updateProperties` method for updating multiple properties.
|
|
6
7
|
* @update 2025-11-24 Added `companyId`, `isAdmin`, `isTemporary` property.
|
|
7
8
|
* Changed to prevent deletion of admin users.
|
|
8
9
|
*
|
|
@@ -52,6 +53,17 @@ export default class User extends FireModel {
|
|
|
52
53
|
static collectionPath = "Users";
|
|
53
54
|
static classProps = classProps;
|
|
54
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Deletes the user document.
|
|
58
|
+
* - Prevents deletion if the user is an administrator.
|
|
59
|
+
* @param {Object} updateOptions - Parameters for deletion.
|
|
60
|
+
* @param {Object|null} [updateOptions.transaction=null] - Firestore transaction object (optional).
|
|
61
|
+
* @param {function|null} [updateOptions.callback=null] - Callback executed after deletion (optional).
|
|
62
|
+
* @param {string|null} [updateOptions.prefix=null] - Optional Firestore path prefix (for server side adapter).
|
|
63
|
+
* @returns {Promise<void>} Resolves when deletion is complete.
|
|
64
|
+
* @throws {Error} If deletion is attempted on an administrator account.
|
|
65
|
+
* @throws {Error} If `docId` is missing, `updateOptions.callback` is not a function, or document is undeletable.
|
|
66
|
+
*/
|
|
55
67
|
async delete(updateOptions = {}) {
|
|
56
68
|
// Prevent deletion of administrator accounts
|
|
57
69
|
if (this.isAdmin) {
|
|
@@ -59,4 +71,25 @@ export default class User extends FireModel {
|
|
|
59
71
|
}
|
|
60
72
|
await super.delete(updateOptions);
|
|
61
73
|
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Update document properties based on provided data.
|
|
77
|
+
* @param {Object} updateData - Key-value pairs of properties to update.
|
|
78
|
+
* @param {Object} updateOptions - Parameters for update operation.
|
|
79
|
+
* @param {Object|null} [updateOptions.transaction=null] - Firestore transaction object.
|
|
80
|
+
* @param {function|null} [updateOptions.callback=null] - Callback executed after update.
|
|
81
|
+
* @param {string|null} [updateOptions.prefix=null] - Optional Firestore path prefix.
|
|
82
|
+
* @returns {Promise<DocumentReference>} Reference to the updated document.
|
|
83
|
+
* @throws {Error} If `updateData` is not a valid object.
|
|
84
|
+
* @throws {Error} If `docId` is not set, or if `updateOptions.callback` is not a function.
|
|
85
|
+
*/
|
|
86
|
+
async updateProperties(updateData = null, updateOptions = {}) {
|
|
87
|
+
if (!updateData || typeof updateData !== "object") {
|
|
88
|
+
throw new Error("updateData must be a valid object.");
|
|
89
|
+
}
|
|
90
|
+
Object.entries(updateData).forEach(([key, value]) => {
|
|
91
|
+
if (this[key] !== undefined) this[key] = value;
|
|
92
|
+
});
|
|
93
|
+
await this.update(updateOptions);
|
|
94
|
+
}
|
|
62
95
|
}
|