|
| 1 | +import type { Model } from '@stacksjs/types' |
| 2 | +import { schema } from '@stacksjs/validation' |
| 3 | + |
| 4 | +export default { |
| 5 | + name: 'ProductUnit', |
| 6 | + table: 'product_units', |
| 7 | + primaryKey: 'id', |
| 8 | + autoIncrement: false, // Using UUID instead of auto-increment |
| 9 | + |
| 10 | + traits: { |
| 11 | + useUuid: true, |
| 12 | + useTimestamps: true, |
| 13 | + useSearch: { |
| 14 | + displayable: ['id', 'name', 'abbreviation', 'type', 'description', 'is_default'], |
| 15 | + searchable: ['name', 'abbreviation', 'type', 'description'], |
| 16 | + sortable: ['name', 'type', 'created_at', 'updated_at'], |
| 17 | + filterable: ['type', 'is_default'], |
| 18 | + }, |
| 19 | + |
| 20 | + useSeeder: { |
| 21 | + count: 10, |
| 22 | + }, |
| 23 | + |
| 24 | + useApi: { |
| 25 | + uri: 'product-units', |
| 26 | + routes: ['index', 'store', 'show'], |
| 27 | + }, |
| 28 | + |
| 29 | + observe: true, |
| 30 | + }, |
| 31 | + |
| 32 | + belongsTo: ['Product'], |
| 33 | + |
| 34 | + attributes: { |
| 35 | + name: { |
| 36 | + required: true, |
| 37 | + order: 1, |
| 38 | + fillable: true, |
| 39 | + validation: { |
| 40 | + rule: schema.string().maxLength(100), |
| 41 | + message: { |
| 42 | + maxLength: 'Name must have a maximum of 100 characters', |
| 43 | + }, |
| 44 | + }, |
| 45 | + factory: (faker) => { |
| 46 | + const units = ['Piece', 'Kilogram', 'Gram', 'Liter', 'Milliliter', 'Meter', 'Centimeter', 'Box', 'Pack', 'Pair'] |
| 47 | + return faker.helpers.arrayElement(units) |
| 48 | + }, |
| 49 | + }, |
| 50 | + |
| 51 | + abbreviation: { |
| 52 | + required: true, |
| 53 | + order: 2, |
| 54 | + fillable: true, |
| 55 | + validation: { |
| 56 | + rule: schema.string().maxLength(10), |
| 57 | + message: { |
| 58 | + maxLength: 'Abbreviation must have a maximum of 10 characters', |
| 59 | + }, |
| 60 | + }, |
| 61 | + factory: (faker) => { |
| 62 | + const abbrs = ['pc', 'kg', 'g', 'L', 'mL', 'm', 'cm', 'box', 'pk', 'pr'] |
| 63 | + return faker.helpers.arrayElement(abbrs) |
| 64 | + }, |
| 65 | + }, |
| 66 | + |
| 67 | + type: { |
| 68 | + required: true, |
| 69 | + order: 3, |
| 70 | + fillable: true, |
| 71 | + validation: { |
| 72 | + rule: schema.string(), |
| 73 | + message: { |
| 74 | + string: 'Type must be a string', |
| 75 | + }, |
| 76 | + }, |
| 77 | + factory: (faker) => { |
| 78 | + const types = ['Weight', 'Volume', 'Length', 'Quantity', 'Size'] |
| 79 | + return faker.helpers.arrayElement(types) |
| 80 | + }, |
| 81 | + }, |
| 82 | + |
| 83 | + description: { |
| 84 | + required: false, |
| 85 | + order: 4, |
| 86 | + fillable: true, |
| 87 | + validation: { |
| 88 | + rule: schema.string().maxLength(255), |
| 89 | + message: { |
| 90 | + maxLength: 'Description must have a maximum of 255 characters', |
| 91 | + }, |
| 92 | + }, |
| 93 | + factory: faker => faker.lorem.sentence(), |
| 94 | + }, |
| 95 | + |
| 96 | + is_default: { |
| 97 | + required: false, |
| 98 | + order: 5, |
| 99 | + fillable: true, |
| 100 | + validation: { |
| 101 | + rule: schema.boolean(), |
| 102 | + message: { |
| 103 | + boolean: 'Default status must be a boolean', |
| 104 | + }, |
| 105 | + }, |
| 106 | + factory: faker => faker.datatype.boolean(0.2), // 20% chance of being default |
| 107 | + }, |
| 108 | + }, |
| 109 | + |
| 110 | + dashboard: { |
| 111 | + highlight: true, |
| 112 | + }, |
| 113 | +} satisfies Model |
0 commit comments