get last sync

This commit is contained in:
Kyle Spearrin 2018-05-15 21:22:39 -04:00
parent 807cca2bd2
commit 42819961b7
2 changed files with 21 additions and 4 deletions

View File

@ -5,6 +5,7 @@ import { CipherType } from 'jslib/enums/cipherType';
import { CipherService } from 'jslib/abstractions/cipher.service';
import { CollectionService } from 'jslib/abstractions/collection.service';
import { FolderService } from 'jslib/abstractions/folder.service';
import { SyncService } from 'jslib/abstractions/sync.service';
import { TotpService } from 'jslib/abstractions/totp.service';
import { Response } from '../models/response';
@ -26,9 +27,14 @@ import { SecureNote } from '../models/secureNote';
export class GetCommand {
constructor(private cipherService: CipherService, private folderService: FolderService,
private collectionService: CollectionService, private totpService: TotpService) { }
private collectionService: CollectionService, private totpService: TotpService,
private syncService: SyncService) { }
async run(object: string, id: string, cmd: program.Command): Promise<Response> {
if (id == null && object !== 'lastsync') {
return Response.badRequest('`id` argument is required.');
}
switch (object.toLowerCase()) {
case 'item':
return await this.getCipher(id);
@ -40,6 +46,8 @@ export class GetCommand {
return await this.getCollection(id);
case 'template':
return await this.getTemplate(id);
case 'lastsync':
return await this.getLastSync();
default:
return Response.badRequest('Unknown object.');
}
@ -139,4 +147,10 @@ export class GetCommand {
const res = new TemplateResponse(template);
return Response.success(res);
}
private async getLastSync() {
const lastSyncDate = await this.syncService.getLastSync();
const res = new StringResponse(lastSyncDate == null ? null : lastSyncDate.toISOString());
return Response.success(res);
}
}

View File

@ -82,11 +82,11 @@ export class Program {
});
program
.command('get <object> <id>')
.command('get <object> [id]')
.description('Get an object.')
.action(async (object, id, cmd) => {
const command = new GetCommand(this.main.cipherService, this.main.folderService,
this.main.collectionService, this.main.totpService);
this.main.collectionService, this.main.totpService, this.main.syncService);
const response = await command.run(object, id, cmd);
this.processResponse(response, cmd);
});
@ -140,7 +140,10 @@ export class Program {
if (response.data != null) {
if (response.data.object === 'string') {
process.stdout.write((response.data as StringResponse).data);
const data = (response.data as StringResponse).data;
if (data != null) {
process.stdout.write(data);
}
} else if (response.data.object === 'list') {
this.printJson((response.data as ListResponse).data, cmd);
} else if (response.data.object === 'template') {