mirror of
https://github.com/directus/directus.git
synced 2026-02-19 10:14:33 -05:00
26 lines
783 B
TypeScript
26 lines
783 B
TypeScript
import { ForbiddenException, InvalidPayloadException } from '../exceptions';
|
|
import { AbstractServiceOptions, PrimaryKey } from '../types';
|
|
import { ItemsService } from './items';
|
|
|
|
export class RevisionsService extends ItemsService {
|
|
constructor(options: AbstractServiceOptions) {
|
|
super('directus_revisions', options);
|
|
}
|
|
|
|
async revert(pk: PrimaryKey): Promise<void> {
|
|
const revision = await super.readOne(pk);
|
|
|
|
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.updateOne(revision.item, revision.data);
|
|
}
|
|
}
|