fix: sync progress add user sub
This commit is contained in:
parent
2faeac523c
commit
e70feb3d27
@ -40,7 +40,6 @@ export enum ObjTypeDto {
|
|||||||
PageSnapshot = 'PAGE_SNAPSHOT',
|
PageSnapshot = 'PAGE_SNAPSHOT',
|
||||||
PageNote = 'PAGE_NOTE',
|
PageNote = 'PAGE_NOTE',
|
||||||
PageAlter = 'PAGE_ALTER',
|
PageAlter = 'PAGE_ALTER',
|
||||||
PageTask = 'PAGE_TASK',
|
|
||||||
Note = 'NOTE',
|
Note = 'NOTE',
|
||||||
Pdf = 'PDF',
|
Pdf = 'PDF',
|
||||||
Removed = 'REMOVED'
|
Removed = 'REMOVED'
|
||||||
|
@ -18,6 +18,7 @@ export interface SyncProgress {
|
|||||||
timestamp: number;
|
timestamp: number;
|
||||||
id: number;
|
id: number;
|
||||||
serverId: number;
|
serverId: number;
|
||||||
|
sub: string;
|
||||||
mode: SyncMode;
|
mode: SyncMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,14 +20,21 @@ import { ObjDto } from '../../../../common/model/obj/obj.dto';
|
|||||||
import { ObjGetCommand } from '../../../../common/command/obj/obj-get.command';
|
import { ObjGetCommand } from '../../../../common/command/obj/obj-get.command';
|
||||||
import { ObjectStoreKeys } from '../../../../common/keys/object.store.keys';
|
import { ObjectStoreKeys } from '../../../../common/keys/object.store.keys';
|
||||||
import { SyncMode, SyncProgress } from '../../../../common/model/sync.model';
|
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>> {
|
export class SyncGetProgressCommand implements ICommand<Promise<SyncProgress | undefined>> {
|
||||||
async execute(): Promise<SyncProgress> {
|
async execute(): Promise<SyncProgress | undefined> {
|
||||||
const sync = await BrowserStorage.get<SyncProgress | undefined>(ObjectStoreKeys.SYNC_PROGRESS);
|
const sync = await BrowserStorage.get<SyncProgress | undefined>(ObjectStoreKeys.SYNC_PROGRESS);
|
||||||
if (sync) return sync;
|
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();
|
const obj = await SyncGetProgressCommand.getFirstObject();
|
||||||
if (!obj) return { timestamp: -1, id: -1, 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 };
|
return { timestamp: obj.createdAt, id: obj.id, serverId: -1, mode: SyncMode.OFF, sub: accessToken.sub };
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getFirstObject(): Promise<ObjDto | undefined> {
|
static async getFirstObject(): Promise<ObjDto | undefined> {
|
||||||
|
@ -22,7 +22,10 @@ import { ObjDto } from '../../../../common/model/obj/obj.dto';
|
|||||||
import { fnDateKeyFormat } from '../../../../common/fn/fn-date-format';
|
import { fnDateKeyFormat } from '../../../../common/fn/fn-date-format';
|
||||||
import { ObjDateIndex } from '../../../../common/command/obj/index/obj-update-index-add.command';
|
import { ObjDateIndex } from '../../../../common/command/obj/index/obj-update-index-add.command';
|
||||||
import { fnConsoleLog } from '../../../../common/fn/fn-console';
|
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>> {
|
export class SyncResetProgressCommand implements ICommand<Promise<void>> {
|
||||||
constructor(private refreshUpdateList = false) {}
|
constructor(private refreshUpdateList = false) {}
|
||||||
@ -30,12 +33,17 @@ export class SyncResetProgressCommand implements ICommand<Promise<void>> {
|
|||||||
const obj = await SyncGetProgressCommand.getFirstObject();
|
const obj = await SyncGetProgressCommand.getFirstObject();
|
||||||
const timestamp = obj?.createdAt || -1;
|
const timestamp = obj?.createdAt || -1;
|
||||||
const id = obj?.id || -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,
|
timestamp,
|
||||||
id,
|
id,
|
||||||
serverId: -1,
|
serverId: -1,
|
||||||
mode: SyncMode.OFF
|
mode: SyncMode.OFF,
|
||||||
});
|
sub: accessToken.sub
|
||||||
|
}).execute();
|
||||||
// await this.resetObjects();
|
// await this.resetObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +104,9 @@ export class SyncMonthCommand implements ICommand<Promise<SyncObjectStatus>> {
|
|||||||
await new SyncSetProgressCommand({
|
await new SyncSetProgressCommand({
|
||||||
id,
|
id,
|
||||||
timestamp,
|
timestamp,
|
||||||
serverId: this.progress.serverId
|
sub: this.progress.sub,
|
||||||
|
serverId: this.progress.serverId,
|
||||||
|
mode: this.progress.mode
|
||||||
}).execute();
|
}).execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user