Skip to content

Commit

Permalink
use date and not datetime for lastConnectionAt
Browse files Browse the repository at this point in the history
  • Loading branch information
CamilleLegeron committed Apr 16, 2024
1 parent 643daca commit 5c06f75
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
24 changes: 12 additions & 12 deletions app/gen-server/lib/HomeDBManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,12 +616,15 @@ export class HomeDBManager extends EventEmitter {
if (!props.isFirstTimeUser) { isWelcomed = true; }
}
if (props.newConnection === true) {
// set last connection time to now (remove milliseconds for compatibility with other
// timestamps in db set by typeorm, and since second level precision is fine)
const nowish = new Date();
nowish.setMilliseconds(0);
user.lastConnectionAt = nowish;
needsSave = true;
// set last connection to today (keep date, remove time)
const today = new Date();
today.setHours(0, 0, 0, 0);
if (today.getFullYear() !== user.lastConnectionAt?.getFullYear() ||
today.getMonth() !== user.lastConnectionAt?.getMonth() ||
today.getDate() !== user.lastConnectionAt?.getDate()){
user.lastConnectionAt = today;
needsSave = true;
}
}
if (needsSave) {
await user.save();
Expand Down Expand Up @@ -710,15 +713,12 @@ export class HomeDBManager extends EventEmitter {
user.name = (profile && (profile.name || email.split('@')[0])) || '';
needUpdate = true;
}
if (profile) {
// set first login time and last connection time to now (remove milliseconds for compatibility with other
if (profile && !user.firstLoginAt) {
// 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)
const nowish = new Date();
nowish.setMilliseconds(0);
user.lastConnectionAt = nowish;
if (!user.firstLoginAt) {
user.firstLoginAt = nowish;
}
user.firstLoginAt = nowish;
needUpdate = true;
}
if (!user.picture && profile && profile.picture) {
Expand Down
4 changes: 1 addition & 3 deletions app/gen-server/migration/1713186031023-UserLastConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import { MigrationInterface, QueryRunner, TableColumn} from 'typeorm';
export class UserLastConnection1713186031023 implements MigrationInterface {

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({
name: 'last_connection_at',
type: datetime,
type: "date",
isNullable: true
}));
}
Expand Down
2 changes: 2 additions & 0 deletions landing.sqbpro
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?><sqlb_project><db path="/home/camillel/Documents/Workspace/donnees_et_territoires/grist-core2/landing.db" readonly="0" foreign_keys="1" case_sensitive_like="0" temp_store="0" wal_autocheckpoint="1000" synchronous="2"/><attached/><window><main_tabs open="structure browser pragmas query" current="3"/></window><tab_structure><column_width id="0" width="300"/><column_width id="1" width="0"/><column_width id="2" width="100"/><column_width id="3" width="5085"/><column_width id="4" width="0"/><expanded_item id="0" parent="1"/><expanded_item id="1" parent="1"/><expanded_item id="2" parent="1"/><expanded_item id="3" parent="1"/></tab_structure><tab_browse><current_table name="4,9:mainacl_rules"/><default_encoding codec=""/><browse_table_settings/></tab_browse><tab_sql><sql name="SQL 1">select * from migrations;
delete from migrations where id = 34;</sql><current_tab id="0"/></tab_sql></sqlb_project>

0 comments on commit 5c06f75

Please sign in to comment.