Skip to content

Commit a2ff45d

Browse files
chore: wip
1 parent 53854f8 commit a2ff45d

16 files changed

+1747
-3
lines changed

app/Models/Activity.ts

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import type { Model } from '@stacksjs/types'
2+
import { faker } from '@stacksjs/faker'
3+
import { schema } from '@stacksjs/validation'
4+
5+
export default {
6+
name: 'Activity',
7+
table: 'activities',
8+
primaryKey: 'id',
9+
autoIncrement: true,
10+
11+
traits: {
12+
useTimestamps: true,
13+
useSoftDeletes: true,
14+
useSeeder: {
15+
count: 10,
16+
},
17+
useApi: true,
18+
likeable: {
19+
table: 'likes',
20+
foreignKey: 'activity_id',
21+
},
22+
},
23+
24+
attributes: {
25+
title: {
26+
fillable: true,
27+
validation: {
28+
rule: schema.string(),
29+
message: {
30+
string: 'title must be a string',
31+
required: 'title is required',
32+
},
33+
},
34+
35+
factory: () => faker.lorem.sentence({ min: 3, max: 6 }),
36+
},
37+
38+
description: {
39+
fillable: true,
40+
validation: {
41+
rule: schema.string().nullable(),
42+
message: {
43+
string: 'description must be a string',
44+
},
45+
},
46+
47+
factory: () => faker.lorem.sentence({ min: 10, max: 25 }),
48+
},
49+
50+
address: {
51+
fillable: true,
52+
validation: {
53+
rule: schema.string(),
54+
message: {
55+
string: 'address must be a string',
56+
required: 'address is required',
57+
},
58+
},
59+
60+
factory: () => faker.location.streetAddress(),
61+
},
62+
63+
latlng: {
64+
fillable: true,
65+
validation: {
66+
rule: schema.string(),
67+
message: {
68+
string: 'latlng must be of format "latitude, longitude"',
69+
required: 'latlng is required',
70+
},
71+
},
72+
73+
factory: () => `${faker.location.latitude()}, ${faker.location.longitude()}`,
74+
},
75+
76+
infoSource: {
77+
fillable: true,
78+
validation: {
79+
rule: schema.enum(['news', 'social-media', 'friends', 'family']),
80+
message: {
81+
string: 'infoSource must be either news, social-media, friends or family',
82+
required: 'infoSource is required',
83+
},
84+
},
85+
86+
factory: () => faker.internet.url(),
87+
},
88+
89+
wereDetained: {
90+
fillable: true,
91+
validation: {
92+
rule: schema.boolean().nullable(),
93+
message: {
94+
string: 'wereDetained must be a boolean or null',
95+
},
96+
},
97+
98+
factory: () => faker.datatype.boolean(),
99+
},
100+
},
101+
} satisfies Model
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { ActivityRequestType } from '@stacksjs/orm'
2+
import { Action } from '@stacksjs/actions'
3+
4+
export default new Action({
5+
name: 'Activity Destroy',
6+
description: 'Activity Destroy ORM Action',
7+
method: 'DELETE',
8+
async handle(request: ActivityRequestType) {
9+
const id = request.getParam('id')
10+
11+
const model = await Activity.findOrFail(Number(id))
12+
13+
model.delete()
14+
15+
return 'Model deleted!'
16+
},
17+
})
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Action } from '@stacksjs/actions'
2+
import { response } from '@stacksjs/router'
3+
4+
export default new Action({
5+
name: 'Activity Index',
6+
description: 'Activity Index ORM Action',
7+
method: 'GET',
8+
async handle() {
9+
const results = Activity.all()
10+
11+
return json.response(response)
12+
},
13+
})
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { ActivityRequestType } from '@stacksjs/orm'
2+
import { Action } from '@stacksjs/actions'
3+
4+
export default new Action({
5+
name: 'Activity Show',
6+
description: 'Activity Show ORM Action',
7+
method: 'GET',
8+
async handle(request: ActivityRequestType) {
9+
const id = request.getParam('id')
10+
11+
return await Activity.findOrFail(Number(id))
12+
},
13+
})
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { ActivityRequestType } from '@stacksjs/orm'
2+
import { Action } from '@stacksjs/actions'
3+
4+
export default new Action({
5+
name: 'Activity Store',
6+
description: 'Activity Store ORM Action',
7+
method: 'POST',
8+
async handle(request: ActivityRequestType) {
9+
await request.validate()
10+
const model = await Activity.create(request.all())
11+
12+
return model
13+
},
14+
})
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { ActivityRequestType } from '@stacksjs/orm'
2+
import { Action } from '@stacksjs/actions'
3+
4+
export default new Action({
5+
name: 'Activity Update',
6+
description: 'Activity Update ORM Action',
7+
method: 'PATCH',
8+
async handle(request: ActivityRequestType) {
9+
await request.validate()
10+
11+
const id = request.getParam('id')
12+
const model = await Activity.findOrFail(Number(id))
13+
14+
return model.update(request.all())
15+
},
16+
})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export type ModelNames = 'Project' | 'SubscriberEmail' | 'AccessToken' | 'Team' | 'Subscriber' | 'Deployment' | 'Release' | 'User' | 'Post' | 'FailedJob' | 'Product' | 'PaymentMethod' | 'Transaction' | 'Job' | 'Subscription' | 'Error'
1+
export type ModelNames = 'Project' | 'SubscriberEmail' | 'AccessToken' | 'Team' | 'Activity' | 'Subscriber' | 'Deployment' | 'Release' | 'User' | 'Post' | 'FailedJob' | 'Product' | 'PaymentMethod' | 'Transaction' | 'Job' | 'Subscription' | 'Error'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export type TableNames = 'projects' | 'subscriber_emails' | 'personal_access_tokens' | 'team_users' | 'teams' | 'subscribers' | 'deployments' | 'releases' | 'team_users' | 'users' | 'posts' | 'failed_jobs' | 'products' | 'payment_methods' | 'transactions' | 'jobs' | 'subscriptions' | 'errors'
1+
export type TableNames = 'projects' | 'subscriber_emails' | 'personal_access_tokens' | 'team_users' | 'teams' | 'activities' | 'subscribers' | 'deployments' | 'releases' | 'team_users' | 'users' | 'posts' | 'failed_jobs' | 'products' | 'payment_methods' | 'transactions' | 'jobs' | 'subscriptions' | 'errors'

storage/framework/orm/routes.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
import { route } from '@stacksjs/router'
22

3+
route.get('activities', 'storage/framework/actions/src/ActivityIndexOrmAction.ts')
4+
5+
route.get('activities/{id}', 'storage/framework/actions/src/ActivityShowOrmAction.ts')
6+
7+
route.post('activities', 'storage/framework/actions/src/ActivityStoreOrmAction.ts')
8+
9+
route.patch('activities/{id}', 'storage/framework/actions/src/ActivityUpdateOrmAction.ts')
10+
11+
route.delete('activities/{id}', 'storage/framework/actions/src/ActivityDestroyOrmAction.ts')
12+
313
route.get('users', 'UserIndexOrmAction')
414

515
route.post('users', 'UserStoreOrmAction')

0 commit comments

Comments
 (0)