import { defineModel, teamMembershipOwnership } from '@stacksjs/orm' import { schema } from '@stacksjs/validation/runtime' export default defineModel({ name: 'Team', table: 'teams', primaryKey: 'id', autoIncrement: true, // The owner column is the primary key: a caller may write the team they are // actually a member of, resolved by the same auth path every other // team-scoped model uses (stacksjs/stacks#2375). ownership: teamMembershipOwnership(), traits: { useUuid: true, useTimestamps: true, useSearch: { displayable: ['id', 'name', 'description', 'memberCount', 'createdAt'], searchable: ['name', 'description'], sortable: ['name', 'createdAt', 'updatedAt', 'memberCount'], filterable: ['status'], }, useSeeder: { count: 5, }, useApi: { uri: 'teams', routes: ['index', 'store', 'show', 'update', 'destroy'], middleware: ['auth'], }, }, hasMany: ['TeamMember', 'TeamInvitation'], attributes: { name: { order: 1, unique: true, fillable: true, validation: { rule: schema.string().required().min(2).max(100), }, factory: faker => faker.company.name(), }, description: { order: 2, fillable: true, validation: { rule: schema.string().max(500), }, factory: faker => faker.company.catchPhrase(), }, memberCount: { order: 3, fillable: false, default: 0, validation: { rule: schema.number().min(0), }, }, status: { order: 4, fillable: true, validation: { rule: schema.string(), }, factory: faker => faker.helpers.arrayElement(['active', 'inactive']), }, }, dashboard: { columns: ['name', 'memberCount', 'status', 'createdAt'], // The row of numbers above the list: teams, active ones, members. regions: { listTop: 'DataStatCards' }, // A count of members is called what it counts. fields: { memberCount: { label: 'Members' }, description: { input: 'longtext' }, }, highlight: true, }, } as const)