@loomcore/api 0.0.16 → 0.0.18
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.
|
@@ -16,8 +16,8 @@ export declare class AuthService extends GenericApiService<IUser> {
|
|
|
16
16
|
};
|
|
17
17
|
userContext: IUserContext;
|
|
18
18
|
} | null>;
|
|
19
|
-
getUserById(id: string): Promise<
|
|
20
|
-
getUserByEmail(email: string): Promise<IUser>;
|
|
19
|
+
getUserById(id: string): Promise<IUser | null>;
|
|
20
|
+
getUserByEmail(email: string): Promise<IUser | null>;
|
|
21
21
|
createUser(userContext: IUserContext, user: IUser): Promise<IUser | null>;
|
|
22
22
|
requestTokenUsingRefreshToken(req: Request): Promise<ITokenResponse | null>;
|
|
23
23
|
changeLoggedInUsersPassword(userContext: IUserContext, body: any): Promise<UpdateResult<import("bson").Document>>;
|
|
@@ -56,20 +56,16 @@ export class AuthService extends GenericApiService {
|
|
|
56
56
|
}
|
|
57
57
|
return loginResponse;
|
|
58
58
|
}
|
|
59
|
-
getUserById(id) {
|
|
59
|
+
async getUserById(id) {
|
|
60
60
|
if (!entityUtils.isValidObjectId(id)) {
|
|
61
61
|
throw new BadRequestError('id is not a valid ObjectId');
|
|
62
62
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return doc;
|
|
66
|
-
});
|
|
63
|
+
const user = await this.findOne(EmptyUserContext, { _id: new ObjectId(id) });
|
|
64
|
+
return user;
|
|
67
65
|
}
|
|
68
|
-
getUserByEmail(email) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return user;
|
|
72
|
-
});
|
|
66
|
+
async getUserByEmail(email) {
|
|
67
|
+
const user = await this.findOne(EmptyUserContext, { email: email.toLowerCase() });
|
|
68
|
+
return user;
|
|
73
69
|
}
|
|
74
70
|
async createUser(userContext, user) {
|
|
75
71
|
const createdUser = await this.create(userContext, user);
|
|
@@ -99,14 +95,16 @@ export class AuthService extends GenericApiService {
|
|
|
99
95
|
return result;
|
|
100
96
|
}
|
|
101
97
|
async changePassword(userContext, queryObject, password) {
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
98
|
+
const updates = { password: password, _lastPasswordChange: moment().utc().toDate() };
|
|
99
|
+
const updatedUsers = await super.update(userContext, queryObject, updates);
|
|
100
|
+
const result = {
|
|
101
|
+
acknowledged: true,
|
|
102
|
+
modifiedCount: updatedUsers.length,
|
|
103
|
+
upsertedId: null,
|
|
104
|
+
upsertedCount: 0,
|
|
105
|
+
matchedCount: updatedUsers.length
|
|
106
|
+
};
|
|
107
|
+
return result;
|
|
110
108
|
}
|
|
111
109
|
async createNewTokens(userId, deviceId, refreshTokenExpiresOn) {
|
|
112
110
|
let createdRefreshTokenObject = null;
|
|
@@ -268,9 +266,8 @@ export class AuthService extends GenericApiService {
|
|
|
268
266
|
if (!entityUtils.isValidObjectId(userId)) {
|
|
269
267
|
throw new BadRequestError('userId is not a valid ObjectId');
|
|
270
268
|
}
|
|
271
|
-
const
|
|
272
|
-
|
|
273
|
-
await this.collection.updateOne(queryObject, { $set: updates });
|
|
269
|
+
const updates = { _lastLoggedIn: moment().utc().toDate() };
|
|
270
|
+
await this.partialUpdateById(EmptyUserContext, userId, updates);
|
|
274
271
|
}
|
|
275
272
|
catch (error) {
|
|
276
273
|
console.log(`Failed to update lastLoggedIn for user ${userId}: ${error}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loomcore/api",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Loom Core Api - An opinionated Node.js api using Typescript, Express, and MongoDb",
|
|
6
6
|
"scripts": {
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"jsonwebtoken": "^9.0.2"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"@loomcore/common": "^0.0.
|
|
47
|
+
"@loomcore/common": "^0.0.9",
|
|
48
48
|
"@sinclair/typebox": "^0.34.31",
|
|
49
49
|
"cookie-parser": "^1.4.6",
|
|
50
50
|
"cors": "^2.8.5",
|