mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
use date and not datetime for lastConnectionAt
This commit is contained in:
parent
643dacafbf
commit
cd8667a333
@ -616,12 +616,15 @@ export class HomeDBManager extends EventEmitter {
|
|||||||
if (!props.isFirstTimeUser) { isWelcomed = true; }
|
if (!props.isFirstTimeUser) { isWelcomed = true; }
|
||||||
}
|
}
|
||||||
if (props.newConnection === true) {
|
if (props.newConnection === true) {
|
||||||
// set last connection time to now (remove milliseconds for compatibility with other
|
// set last connection to today (keep date, remove time)
|
||||||
// timestamps in db set by typeorm, and since second level precision is fine)
|
const today = new Date();
|
||||||
const nowish = new Date();
|
today.setHours(0, 0, 0, 0);
|
||||||
nowish.setMilliseconds(0);
|
if (today.getFullYear() !== user.lastConnectionAt?.getFullYear() ||
|
||||||
user.lastConnectionAt = nowish;
|
today.getMonth() !== user.lastConnectionAt?.getMonth() ||
|
||||||
needsSave = true;
|
today.getDate() !== user.lastConnectionAt?.getDate()){
|
||||||
|
user.lastConnectionAt = today;
|
||||||
|
needsSave = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (needsSave) {
|
if (needsSave) {
|
||||||
await user.save();
|
await user.save();
|
||||||
@ -710,15 +713,12 @@ export class HomeDBManager extends EventEmitter {
|
|||||||
user.name = (profile && (profile.name || email.split('@')[0])) || '';
|
user.name = (profile && (profile.name || email.split('@')[0])) || '';
|
||||||
needUpdate = true;
|
needUpdate = true;
|
||||||
}
|
}
|
||||||
if (profile) {
|
if (profile && !user.firstLoginAt) {
|
||||||
// set first login time and last connection time to now (remove milliseconds for compatibility with other
|
// set first login time to now (remove milliseconds for compatibility with other
|
||||||
// timestamps in db set by typeorm, and since second level precision is fine)
|
// timestamps in db set by typeorm, and since second level precision is fine)
|
||||||
const nowish = new Date();
|
const nowish = new Date();
|
||||||
nowish.setMilliseconds(0);
|
nowish.setMilliseconds(0);
|
||||||
user.lastConnectionAt = nowish;
|
user.firstLoginAt = nowish;
|
||||||
if (!user.firstLoginAt) {
|
|
||||||
user.firstLoginAt = nowish;
|
|
||||||
}
|
|
||||||
needUpdate = true;
|
needUpdate = true;
|
||||||
}
|
}
|
||||||
if (!user.picture && profile && profile.picture) {
|
if (!user.picture && profile && profile.picture) {
|
||||||
|
@ -3,11 +3,9 @@ import { MigrationInterface, QueryRunner, TableColumn} from 'typeorm';
|
|||||||
export class UserLastConnection1713186031023 implements MigrationInterface {
|
export class UserLastConnection1713186031023 implements MigrationInterface {
|
||||||
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||||
const sqlite = queryRunner.connection.driver.options.type === 'sqlite';
|
|
||||||
const datetime = sqlite ? "datetime" : "timestamp with time zone";
|
|
||||||
await queryRunner.addColumn('users', new TableColumn({
|
await queryRunner.addColumn('users', new TableColumn({
|
||||||
name: 'last_connection_at',
|
name: 'last_connection_at',
|
||||||
type: datetime,
|
type: "date",
|
||||||
isNullable: true
|
isNullable: true
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user