import type Computer from '#models/computer' /** * Transforms a Computer into the shape exposed on the public share page. * Unlike the regular serialize(), this never leaks the owner id, and only * includes sellPrice/cost when the owner explicitly enabled that on the * share settings. */ export default class ComputerPublicTransformer { static transform(computer: typeof Computer.prototype) { return { id: computer.id, title: computer.title, gpuScore: computer.gpuScore, cpuScore: computer.cpuScore, globalScore: computer.globalScore, state: { name: computer.state.name }, sellPrice: computer.shareShowSellPrice ? computer.sellPrice : null, cost: computer.shareShowCost ? computer.cost : null, pictures: computer.pictures .map((picture) => ({ link: picture.link, order: picture.order })) .sort((a, b) => a.order - b.order), components: computer.components.map((component) => ({ id: component.id, name: component.name, type: { name: component.type.name }, })), } } }