diff --git a/src/controllers/api/addPendingFriendController.ts b/src/controllers/api/addPendingFriendController.ts index c045d044..0ba548f4 100644 --- a/src/controllers/api/addPendingFriendController.ts +++ b/src/controllers/api/addPendingFriendController.ts @@ -1,4 +1,4 @@ -import { toOid } from "@/src/helpers/inventoryHelpers"; +import { toMongoDate, toOid } from "@/src/helpers/inventoryHelpers"; import { getJSONfromString } from "@/src/helpers/stringHelpers"; import { Friendship } from "@/src/models/friendModel"; import { Account } from "@/src/models/loginModel"; @@ -37,6 +37,7 @@ export const addPendingFriendController: RequestHandler = async (req, res) => { const friendInfo: IFriendInfo = { _id: toOid(account._id), DisplayName: account.DisplayName, + LastLogin: toMongoDate(account.LastLogin), Note: payload.message }; await addInventoryDataToFriendInfo(friendInfo); diff --git a/src/controllers/api/addToGuildController.ts b/src/controllers/api/addToGuildController.ts index 4ae01b7b..aeda4214 100644 --- a/src/controllers/api/addToGuildController.ts +++ b/src/controllers/api/addToGuildController.ts @@ -1,3 +1,4 @@ +import { toMongoDate } from "@/src/helpers/inventoryHelpers"; import { Guild, GuildMember } from "@/src/models/guildModel"; import { Account } from "@/src/models/loginModel"; import { addInventoryDataToFriendInfo, areFriends } from "@/src/services/friendService"; @@ -75,6 +76,7 @@ export const addToGuildController: RequestHandler = async (req, res) => { const member: IGuildMemberClient = { _id: { $oid: account._id.toString() }, DisplayName: account.DisplayName, + LastLogin: toMongoDate(account.LastLogin), Rank: 7, Status: 2 }; diff --git a/src/controllers/api/loginController.ts b/src/controllers/api/loginController.ts index 07a9b9da..f1eab10a 100644 --- a/src/controllers/api/loginController.ts +++ b/src/controllers/api/loginController.ts @@ -48,7 +48,8 @@ export const loginController: RequestHandler = async (request, response) => { ConsentNeeded: false, TrackedSettings: [], Nonce: nonce, - BuildLabel: buildLabel + BuildLabel: buildLabel, + LastLogin: new Date() }); logger.debug("created new account"); response.json(createLoginResponse(myAddress, newAccount, buildLabel)); @@ -93,6 +94,7 @@ export const loginController: RequestHandler = async (request, response) => { account.Nonce = nonce; account.CountryCode = loginRequest.lang?.toUpperCase() ?? "EN"; account.BuildLabel = buildLabel; + account.LastLogin = new Date(); } await account.save(); diff --git a/src/helpers/customHelpers/customHelpers.ts b/src/helpers/customHelpers/customHelpers.ts index a0163833..02defc8c 100644 --- a/src/helpers/customHelpers/customHelpers.ts +++ b/src/helpers/customHelpers/customHelpers.ts @@ -48,7 +48,8 @@ const toDatabaseAccount = (createAccount: IAccountCreation): IDatabaseAccountReq CrossPlatformAllowed: true, ForceLogoutVersion: 0, TrackedSettings: [], - Nonce: 0 + Nonce: 0, + LastLogin: new Date() } satisfies IDatabaseAccountRequiredFields; }; diff --git a/src/models/loginModel.ts b/src/models/loginModel.ts index fe9d0b5f..0f83c0cb 100644 --- a/src/models/loginModel.ts +++ b/src/models/loginModel.ts @@ -22,6 +22,7 @@ const databaseAccountSchema = new Schema( Nonce: { type: Number, default: 0 }, BuildLabel: String, Dropped: Boolean, + LastLogin: { type: Date, default: 0 }, LatestEventMessageDate: { type: Date, default: 0 }, LastLoginRewardDate: { type: Number, default: 0 }, LoginDays: { type: Number, default: 1 } diff --git a/src/services/friendService.ts b/src/services/friendService.ts index a17c9750..6243f93b 100644 --- a/src/services/friendService.ts +++ b/src/services/friendService.ts @@ -4,9 +4,12 @@ import { config } from "./configService"; import { Account } from "../models/loginModel"; import { Types } from "mongoose"; import { Friendship } from "../models/friendModel"; +import { toMongoDate } from "../helpers/inventoryHelpers"; export const addAccountDataToFriendInfo = async (info: IFriendInfo): Promise => { - info.DisplayName = (await Account.findById(info._id.$oid, "DisplayName"))!.DisplayName; + const account = (await Account.findById(info._id.$oid, "DisplayName LastLogin"))!; + info.DisplayName = account.DisplayName; + info.LastLogin = toMongoDate(account.LastLogin); }; export const addInventoryDataToFriendInfo = async (info: IFriendInfo): Promise => { diff --git a/src/types/loginTypes.ts b/src/types/loginTypes.ts index 5a7f9e46..159d39e9 100644 --- a/src/types/loginTypes.ts +++ b/src/types/loginTypes.ts @@ -17,6 +17,7 @@ export interface IDatabaseAccountRequiredFields extends IAccountAndLoginResponse email: string; password: string; BuildLabel?: string; + LastLogin: Date; } export interface IDatabaseAccount extends IDatabaseAccountRequiredFields {