feat: track LastLogin to provide it for friends & clan members (#2013)
Reviewed-on: #2013 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
This commit is contained in:
parent
b987e01811
commit
3bcac1459b
@ -1,4 +1,4 @@
|
|||||||
import { toOid } from "@/src/helpers/inventoryHelpers";
|
import { toMongoDate, toOid } from "@/src/helpers/inventoryHelpers";
|
||||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
||||||
import { Friendship } from "@/src/models/friendModel";
|
import { Friendship } from "@/src/models/friendModel";
|
||||||
import { Account } from "@/src/models/loginModel";
|
import { Account } from "@/src/models/loginModel";
|
||||||
@ -37,6 +37,7 @@ export const addPendingFriendController: RequestHandler = async (req, res) => {
|
|||||||
const friendInfo: IFriendInfo = {
|
const friendInfo: IFriendInfo = {
|
||||||
_id: toOid(account._id),
|
_id: toOid(account._id),
|
||||||
DisplayName: account.DisplayName,
|
DisplayName: account.DisplayName,
|
||||||
|
LastLogin: toMongoDate(account.LastLogin),
|
||||||
Note: payload.message
|
Note: payload.message
|
||||||
};
|
};
|
||||||
await addInventoryDataToFriendInfo(friendInfo);
|
await addInventoryDataToFriendInfo(friendInfo);
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { toMongoDate } from "@/src/helpers/inventoryHelpers";
|
||||||
import { Guild, GuildMember } from "@/src/models/guildModel";
|
import { Guild, GuildMember } from "@/src/models/guildModel";
|
||||||
import { Account } from "@/src/models/loginModel";
|
import { Account } from "@/src/models/loginModel";
|
||||||
import { addInventoryDataToFriendInfo, areFriends } from "@/src/services/friendService";
|
import { addInventoryDataToFriendInfo, areFriends } from "@/src/services/friendService";
|
||||||
@ -75,6 +76,7 @@ export const addToGuildController: RequestHandler = async (req, res) => {
|
|||||||
const member: IGuildMemberClient = {
|
const member: IGuildMemberClient = {
|
||||||
_id: { $oid: account._id.toString() },
|
_id: { $oid: account._id.toString() },
|
||||||
DisplayName: account.DisplayName,
|
DisplayName: account.DisplayName,
|
||||||
|
LastLogin: toMongoDate(account.LastLogin),
|
||||||
Rank: 7,
|
Rank: 7,
|
||||||
Status: 2
|
Status: 2
|
||||||
};
|
};
|
||||||
|
@ -48,7 +48,8 @@ export const loginController: RequestHandler = async (request, response) => {
|
|||||||
ConsentNeeded: false,
|
ConsentNeeded: false,
|
||||||
TrackedSettings: [],
|
TrackedSettings: [],
|
||||||
Nonce: nonce,
|
Nonce: nonce,
|
||||||
BuildLabel: buildLabel
|
BuildLabel: buildLabel,
|
||||||
|
LastLogin: new Date()
|
||||||
});
|
});
|
||||||
logger.debug("created new account");
|
logger.debug("created new account");
|
||||||
response.json(createLoginResponse(myAddress, newAccount, buildLabel));
|
response.json(createLoginResponse(myAddress, newAccount, buildLabel));
|
||||||
@ -93,6 +94,7 @@ export const loginController: RequestHandler = async (request, response) => {
|
|||||||
account.Nonce = nonce;
|
account.Nonce = nonce;
|
||||||
account.CountryCode = loginRequest.lang?.toUpperCase() ?? "EN";
|
account.CountryCode = loginRequest.lang?.toUpperCase() ?? "EN";
|
||||||
account.BuildLabel = buildLabel;
|
account.BuildLabel = buildLabel;
|
||||||
|
account.LastLogin = new Date();
|
||||||
}
|
}
|
||||||
await account.save();
|
await account.save();
|
||||||
|
|
||||||
|
@ -48,7 +48,8 @@ const toDatabaseAccount = (createAccount: IAccountCreation): IDatabaseAccountReq
|
|||||||
CrossPlatformAllowed: true,
|
CrossPlatformAllowed: true,
|
||||||
ForceLogoutVersion: 0,
|
ForceLogoutVersion: 0,
|
||||||
TrackedSettings: [],
|
TrackedSettings: [],
|
||||||
Nonce: 0
|
Nonce: 0,
|
||||||
|
LastLogin: new Date()
|
||||||
} satisfies IDatabaseAccountRequiredFields;
|
} satisfies IDatabaseAccountRequiredFields;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ const databaseAccountSchema = new Schema<IDatabaseAccountJson>(
|
|||||||
Nonce: { type: Number, default: 0 },
|
Nonce: { type: Number, default: 0 },
|
||||||
BuildLabel: String,
|
BuildLabel: String,
|
||||||
Dropped: Boolean,
|
Dropped: Boolean,
|
||||||
|
LastLogin: { type: Date, default: 0 },
|
||||||
LatestEventMessageDate: { type: Date, default: 0 },
|
LatestEventMessageDate: { type: Date, default: 0 },
|
||||||
LastLoginRewardDate: { type: Number, default: 0 },
|
LastLoginRewardDate: { type: Number, default: 0 },
|
||||||
LoginDays: { type: Number, default: 1 }
|
LoginDays: { type: Number, default: 1 }
|
||||||
|
@ -4,9 +4,12 @@ import { config } from "./configService";
|
|||||||
import { Account } from "../models/loginModel";
|
import { Account } from "../models/loginModel";
|
||||||
import { Types } from "mongoose";
|
import { Types } from "mongoose";
|
||||||
import { Friendship } from "../models/friendModel";
|
import { Friendship } from "../models/friendModel";
|
||||||
|
import { toMongoDate } from "../helpers/inventoryHelpers";
|
||||||
|
|
||||||
export const addAccountDataToFriendInfo = async (info: IFriendInfo): Promise<void> => {
|
export const addAccountDataToFriendInfo = async (info: IFriendInfo): Promise<void> => {
|
||||||
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<void> => {
|
export const addInventoryDataToFriendInfo = async (info: IFriendInfo): Promise<void> => {
|
||||||
|
@ -17,6 +17,7 @@ export interface IDatabaseAccountRequiredFields extends IAccountAndLoginResponse
|
|||||||
email: string;
|
email: string;
|
||||||
password: string;
|
password: string;
|
||||||
BuildLabel?: string;
|
BuildLabel?: string;
|
||||||
|
LastLogin: Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IDatabaseAccount extends IDatabaseAccountRequiredFields {
|
export interface IDatabaseAccount extends IDatabaseAccountRequiredFields {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user