UNPKG

@gameroom/cli

Version:

A command line tool for Gameroom

25 lines (23 loc) 785 B
const { models } = require('@gameroom/kit') module.exports = class Image { constructor(data) { if (!data) data = {} this.created_at = data.created_at this.height = data.height this.id = data.id this.position = data.position this.product_id = data.product_id this.src = data.src this.updated_at = data.updated_at this.variant_ids = data.variant_ids this.width = data.width return this.clean() } static async forId(id) { const images = await models.Image.get({ filter: { key: 'imageable_id', value: id }, sort: [{ position: 1 }] }) return images.reduce((a, i) => [...a, new Image({ src: i.image })], []) } clean() { return Object.keys(this).reduce((a, i) => this[i] !== undefined ? { ...a, [i]: this[i] } : a, {}) } }