UNPKG

@jrmc/adonis-attachment

Version:

Turn any field on your Lucid model to an attachment data type

30 lines (29 loc) 891 B
import { AttachmentRecordService } from '../src/services/attachment/index.js'; export default class RegenerateService { #Model; #row; #options; model(Model, options = {}) { this.#Model = Model; this.#options = options; return this; } row(row, options = {}) { this.#row = row; this.#options = options; return this; } async run() { if (this.#row) { const record = new AttachmentRecordService(this.#row); return record.regenerateVariants(this.#options); } else if (this.#Model) { const entities = await this.#Model.all(); return Promise.all(entities.map(async (entity) => { const record = new AttachmentRecordService(entity); return record.regenerateVariants(this.#options); })); } } }