mirror of
https://github.com/directus/directus.git
synced 2026-02-19 10:14:33 -05:00
* Disable accountability for 'directus_activity' and 'directus_revisions' * Use services to save accountability records - Import ActivityService/RevisionsService in ItemsService and ItemsService in ActivityService/RevisionsService from "./internal" to prevent circular dependencies issue - Use type PrimaryKey instead of number for onRevisionCreate method (was already used to collect PrimaryKeys in payload.ts anyway) * Use index.ts to load activity & revision services * Use for instead of forEach Co-authored-by: rijkvanzanten <rijkvanzanten@me.com>
26 lines
783 B
TypeScript
26 lines
783 B
TypeScript
import { ForbiddenException, InvalidPayloadException } from '../exceptions';
|
|
import { AbstractServiceOptions, PrimaryKey } from '../types';
|
|
import { ItemsService } from './index';
|
|
|
|
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);
|
|
}
|
|
}
|