fix: sync progress add user sub

This commit is contained in:
Michal Szczepanski 2023-10-18 03:38:06 +02:00
parent 2faeac523c
commit e70feb3d27
5 changed files with 27 additions and 10 deletions

View File

@ -40,7 +40,6 @@ export enum ObjTypeDto {
PageSnapshot = 'PAGE_SNAPSHOT',
PageNote = 'PAGE_NOTE',
PageAlter = 'PAGE_ALTER',
PageTask = 'PAGE_TASK',
Note = 'NOTE',
Pdf = 'PDF',
Removed = 'REMOVED'

View File

@ -18,6 +18,7 @@ export interface SyncProgress {
timestamp: number;
id: number;
serverId: number;
sub: string;
mode: SyncMode;
}

View File

@ -20,14 +20,21 @@ import { ObjDto } from '../../../../common/model/obj/obj.dto';
import { ObjGetCommand } from '../../../../common/command/obj/obj-get.command';
import { ObjectStoreKeys } from '../../../../common/keys/object.store.keys';
import { SyncMode, SyncProgress } from '../../../../common/model/sync.model';
import { TokenStorageGetCommand } from '../../../../common/command/server/token/token-storage-get.command';
import { TokenDecodeCommand } from '../../../../common/command/server/token/token-decode.command';
export class SyncGetProgressCommand implements ICommand<Promise<SyncProgress>> {
async execute(): Promise<SyncProgress> {
export class SyncGetProgressCommand implements ICommand<Promise<SyncProgress | undefined>> {
async execute(): Promise<SyncProgress | undefined> {
const sync = await BrowserStorage.get<SyncProgress | undefined>(ObjectStoreKeys.SYNC_PROGRESS);
if (sync) return sync;
const token = await new TokenStorageGetCommand().execute();
if (!token) return;
const accessToken = new TokenDecodeCommand(token?.access_token).execute();
const obj = await SyncGetProgressCommand.getFirstObject();
if (!obj) return { timestamp: -1, id: -1, serverId: -1, mode: SyncMode.OFF };
return { timestamp: obj.createdAt, id: obj.id, serverId: -1, mode: SyncMode.OFF };
if (!obj) return { timestamp: -1, id: -1, serverId: -1, mode: SyncMode.OFF, sub: accessToken.sub };
return { timestamp: obj.createdAt, id: obj.id, serverId: -1, mode: SyncMode.OFF, sub: accessToken.sub };
}
static async getFirstObject(): Promise<ObjDto | undefined> {

View File

@ -22,7 +22,10 @@ import { ObjDto } from '../../../../common/model/obj/obj.dto';
import { fnDateKeyFormat } from '../../../../common/fn/fn-date-format';
import { ObjDateIndex } from '../../../../common/command/obj/index/obj-update-index-add.command';
import { fnConsoleLog } from '../../../../common/fn/fn-console';
import { SyncMode, SyncProgress } from '../../../../common/model/sync.model';
import { SyncMode } from '../../../../common/model/sync.model';
import { SyncSetProgressCommand } from './sync-set-progress.command';
import { TokenStorageGetCommand } from '../../../../common/command/server/token/token-storage-get.command';
import { TokenDecodeCommand } from '../../../../common/command/server/token/token-decode.command';
export class SyncResetProgressCommand implements ICommand<Promise<void>> {
constructor(private refreshUpdateList = false) {}
@ -30,12 +33,17 @@ export class SyncResetProgressCommand implements ICommand<Promise<void>> {
const obj = await SyncGetProgressCommand.getFirstObject();
const timestamp = obj?.createdAt || -1;
const id = obj?.id || -1;
await BrowserStorage.set<SyncProgress>(ObjectStoreKeys.SYNC_PROGRESS, {
const token = await new TokenStorageGetCommand().execute();
if (!token) return;
const accessToken = new TokenDecodeCommand(token?.access_token).execute();
await new SyncSetProgressCommand({
timestamp,
id,
serverId: -1,
mode: SyncMode.OFF
});
mode: SyncMode.OFF,
sub: accessToken.sub
}).execute();
// await this.resetObjects();
}

View File

@ -104,7 +104,9 @@ export class SyncMonthCommand implements ICommand<Promise<SyncObjectStatus>> {
await new SyncSetProgressCommand({
id,
timestamp,
serverId: this.progress.serverId
sub: this.progress.sub,
serverId: this.progress.serverId,
mode: this.progress.mode
}).execute();
}
}