mirror of
https://github.com/directus/directus.git
synced 2026-02-01 15:34:57 -05:00
29 lines
899 B
TypeScript
29 lines
899 B
TypeScript
import { ItemsService } from './items';
|
|
import { AbstractServiceOptions, PrimaryKey, Revision } from '../types';
|
|
import { InvalidPayloadException, ForbiddenException } from '../exceptions';
|
|
|
|
/**
|
|
* @TODO only return data / delta based on permissions you have for the requested collection
|
|
*/
|
|
|
|
export class RevisionsService extends ItemsService {
|
|
constructor(options: AbstractServiceOptions) {
|
|
super('directus_revisions', options);
|
|
}
|
|
|
|
async revert(pk: PrimaryKey) {
|
|
const revision = (await super.readByKey(pk)) as Revision | null;
|
|
if (!revision) throw new ForbiddenException();
|
|
|
|
if (!revision.data) throw new InvalidPayloadException(`Revision doesn't contain data to revert to`);
|
|
|
|
const service = new ItemsService(revision.collection, {
|
|
accountability: this.accountability,
|
|
knex: this.knex,
|
|
schema: this.schema,
|
|
});
|
|
|
|
await service.update(revision.data, revision.item);
|
|
}
|
|
}
|