UNPKG

@jrmc/adonis-attachment

Version:

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

30 lines (29 loc) 884 B
import RecordWithAttachment from '../src/services/record_with_attachment.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 RecordWithAttachment(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 RecordWithAttachment(entity); return record.regenerateVariants(this.#options); })); } } }