@primstack/cli 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generators/crud/templates/drizzle-table.ts.template +12 -0
- package/dist/generators/crud/templates/handlers.ts.template +136 -0
- package/dist/generators/crud/templates/routes.ts.template +21 -0
- package/dist/generators/crud/templates/schema.ts.template +20 -0
- package/dist/index.js +9618 -0
- package/dist/integrations/analytics/providers/amplitude/templates/src/analytics/index.ts.template +79 -0
- package/dist/integrations/analytics/providers/amplitude/templates/src/analytics/types.ts.template +12 -0
- package/dist/integrations/analytics/providers/mixpanel/templates/src/analytics/index.ts.template +62 -0
- package/dist/integrations/analytics/providers/mixpanel/templates/src/analytics/types.ts.template +12 -0
- package/dist/integrations/analytics/providers/posthog/templates/src/analytics/index.ts.template +67 -0
- package/dist/integrations/analytics/providers/posthog/templates/src/analytics/types.ts.template +12 -0
- package/dist/integrations/auth/providers/authjoy/templates/api/src/middleware/auth.ts.template +89 -0
- package/dist/integrations/auth/providers/authjoy/templates/api/src/routes/auth.ts.template +27 -0
- package/dist/integrations/auth/providers/authjoy/templates/web/src/components/AuthProvider.tsx.template +40 -0
- package/dist/integrations/auth/providers/authjoy/templates/web/src/hooks/use-auth.ts.template +71 -0
- package/dist/integrations/auth/providers/authjoy/templates/web/src/lib/auth.ts.template +59 -0
- package/dist/integrations/auth/providers/authjoy/templates/web/src/pages/account.tsx.template +84 -0
- package/dist/integrations/auth/providers/authjoy/templates/web/src/pages/login.tsx.template +73 -0
- package/dist/integrations/cache/providers/memory/templates/src/cache/index.ts.template +43 -0
- package/dist/integrations/cache/providers/memory/templates/src/cache/types.ts.template +3 -0
- package/dist/integrations/cache/providers/redis/templates/src/cache/index.ts.template +37 -0
- package/dist/integrations/cache/providers/redis/templates/src/cache/types.ts.template +3 -0
- package/dist/integrations/cache/providers/valkey/templates/src/cache/index.ts.template +38 -0
- package/dist/integrations/cache/providers/valkey/templates/src/cache/types.ts.template +3 -0
- package/dist/integrations/db/providers/postgres/templates/drizzle.config.ts.template +10 -0
- package/dist/integrations/db/providers/postgres/templates/src/db/index.ts.template +13 -0
- package/dist/integrations/db/providers/postgres/templates/src/db/migrate.ts.template +19 -0
- package/dist/integrations/db/providers/postgres/templates/src/db/schema/index.ts.template +1 -0
- package/dist/integrations/db/providers/postgres/templates/src/db/schema/users.ts.template +12 -0
- package/dist/integrations/db/providers/postgres/templates/src/db/seed.ts.template +28 -0
- package/dist/integrations/db/providers/sqlite/templates/drizzle.config.ts.template +10 -0
- package/dist/integrations/db/providers/sqlite/templates/src/db/index.ts.template +10 -0
- package/dist/integrations/db/providers/sqlite/templates/src/db/schema/index.ts.template +1 -0
- package/dist/integrations/db/providers/sqlite/templates/src/db/schema/users.ts.template +12 -0
- package/dist/integrations/db/providers/sqlite/templates/src/db/seed.ts.template +28 -0
- package/dist/integrations/db/providers/supabase/templates/drizzle.config.ts.template +10 -0
- package/dist/integrations/db/providers/supabase/templates/src/db/index.ts.template +13 -0
- package/dist/integrations/db/providers/supabase/templates/src/db/migrate.ts.template +19 -0
- package/dist/integrations/db/providers/supabase/templates/src/db/schema/index.ts.template +1 -0
- package/dist/integrations/db/providers/supabase/templates/src/db/schema/users.ts.template +12 -0
- package/dist/integrations/db/providers/supabase/templates/src/db/seed.ts.template +28 -0
- package/dist/integrations/db/providers/turso/templates/drizzle.config.ts.template +11 -0
- package/dist/integrations/db/providers/turso/templates/src/db/index.ts.template +14 -0
- package/dist/integrations/db/providers/turso/templates/src/db/schema/index.ts.template +1 -0
- package/dist/integrations/db/providers/turso/templates/src/db/schema/users.ts.template +12 -0
- package/dist/integrations/db/providers/turso/templates/src/db/seed.ts.template +28 -0
- package/dist/integrations/email/providers/nodemailer/templates/src/email/index.ts.template +24 -0
- package/dist/integrations/email/providers/nodemailer/templates/src/email/templates/index.ts.template +1 -0
- package/dist/integrations/email/providers/nodemailer/templates/src/email/templates/welcome.ts.template +7 -0
- package/dist/integrations/email/providers/nodemailer/templates/src/email/types.ts.template +7 -0
- package/dist/integrations/email/providers/resend/templates/src/email/index.ts.template +18 -0
- package/dist/integrations/email/providers/resend/templates/src/email/templates/index.ts.template +1 -0
- package/dist/integrations/email/providers/resend/templates/src/email/templates/welcome.ts.template +7 -0
- package/dist/integrations/email/providers/resend/templates/src/email/types.ts.template +7 -0
- package/dist/integrations/email/providers/sendgrid/templates/src/email/index.ts.template +16 -0
- package/dist/integrations/email/providers/sendgrid/templates/src/email/templates/index.ts.template +1 -0
- package/dist/integrations/email/providers/sendgrid/templates/src/email/templates/welcome.ts.template +7 -0
- package/dist/integrations/email/providers/sendgrid/templates/src/email/types.ts.template +7 -0
- package/dist/integrations/flags/providers/local/templates/api/src/lib/flags.ts.template +97 -0
- package/dist/integrations/flags/providers/local/templates/api/src/routes/flags.ts.template +36 -0
- package/dist/integrations/flags/providers/local/templates/flags.json.template +8 -0
- package/dist/integrations/flags/providers/local/templates/web/src/hooks/use-flag.ts.template +60 -0
- package/dist/integrations/logging/providers/axiom/templates/src/logging/index.ts.template +56 -0
- package/dist/integrations/logging/providers/axiom/templates/src/logging/types.ts.template +5 -0
- package/dist/integrations/logging/providers/pino/templates/src/logging/index.ts.template +21 -0
- package/dist/integrations/logging/providers/pino/templates/src/logging/types.ts.template +5 -0
- package/dist/integrations/logging/providers/winston/templates/src/logging/index.ts.template +30 -0
- package/dist/integrations/logging/providers/winston/templates/src/logging/types.ts.template +5 -0
- package/dist/integrations/monitor/providers/datadog/templates/src/monitor/index.ts.template +78 -0
- package/dist/integrations/monitor/providers/datadog/templates/src/monitor/types.ts.template +12 -0
- package/dist/integrations/monitor/providers/newrelic/templates/src/monitor/index.ts.template +60 -0
- package/dist/integrations/monitor/providers/newrelic/templates/src/monitor/types.ts.template +12 -0
- package/dist/integrations/monitor/providers/sentry/templates/src/monitor/index.ts.template +70 -0
- package/dist/integrations/monitor/providers/sentry/templates/src/monitor/types.ts.template +12 -0
- package/dist/integrations/queue/providers/bullmq/templates/src/queue/index.ts.template +56 -0
- package/dist/integrations/queue/providers/bullmq/templates/src/queue/types.ts.template +10 -0
- package/dist/integrations/queue/providers/memory/templates/src/queue/index.ts.template +73 -0
- package/dist/integrations/queue/providers/memory/templates/src/queue/types.ts.template +10 -0
- package/dist/integrations/queue/providers/pgboss/templates/src/queue/index.ts.template +34 -0
- package/dist/integrations/queue/providers/pgboss/templates/src/queue/types.ts.template +10 -0
- package/dist/integrations/ratelimit/providers/memory/templates/src/ratelimit/index.ts.template +95 -0
- package/dist/integrations/ratelimit/providers/memory/templates/src/ratelimit/types.ts.template +12 -0
- package/dist/integrations/ratelimit/providers/rate-limiter-flexible/templates/src/ratelimit/index.ts.template +80 -0
- package/dist/integrations/ratelimit/providers/rate-limiter-flexible/templates/src/ratelimit/types.ts.template +12 -0
- package/dist/integrations/ratelimit/providers/upstash/templates/src/ratelimit/index.ts.template +67 -0
- package/dist/integrations/ratelimit/providers/upstash/templates/src/ratelimit/types.ts.template +12 -0
- package/dist/integrations/schedule/providers/bullmq/templates/src/schedule/index.ts.template +81 -0
- package/dist/integrations/schedule/providers/bullmq/templates/src/schedule/types.ts.template +10 -0
- package/dist/integrations/schedule/providers/croner/templates/src/schedule/index.ts.template +47 -0
- package/dist/integrations/schedule/providers/croner/templates/src/schedule/types.ts.template +10 -0
- package/dist/integrations/schedule/providers/node-cron/templates/src/schedule/index.ts.template +45 -0
- package/dist/integrations/schedule/providers/node-cron/templates/src/schedule/types.ts.template +10 -0
- package/dist/integrations/search/providers/algolia/templates/src/search/index.ts.template +52 -0
- package/dist/integrations/search/providers/algolia/templates/src/search/types.ts.template +18 -0
- package/dist/integrations/search/providers/meilisearch/templates/src/search/index.ts.template +49 -0
- package/dist/integrations/search/providers/meilisearch/templates/src/search/types.ts.template +18 -0
- package/dist/integrations/search/providers/typesense/templates/src/search/index.ts.template +71 -0
- package/dist/integrations/search/providers/typesense/templates/src/search/types.ts.template +35 -0
- package/dist/integrations/storage/providers/local/templates/src/storage/index.ts.template +69 -0
- package/dist/integrations/storage/providers/local/templates/src/storage/types.ts.template +12 -0
- package/dist/integrations/storage/providers/r2/templates/src/storage/index.ts.template +80 -0
- package/dist/integrations/storage/providers/r2/templates/src/storage/types.ts.template +12 -0
- package/dist/integrations/storage/providers/s3/templates/src/storage/index.ts.template +78 -0
- package/dist/integrations/storage/providers/s3/templates/src/storage/types.ts.template +12 -0
- package/dist/integrations/stripe/templates/api/src/lib/stripe.ts.template +259 -0
- package/dist/integrations/stripe/templates/api/src/routes/stripe-webhooks.ts.template +284 -0
- package/dist/integrations/stripe/templates/api/stripe.config.ts.template +178 -0
- package/dist/integrations/stripe/templates/shared/src/pricing.ts.template +117 -0
- package/dist/integrations/stripe/templates/shared/src/stripe-types.ts.template +133 -0
- package/dist/integrations/stripe/templates/web/src/components/billing-settings.tsx.template +123 -0
- package/dist/integrations/stripe/templates/web/src/components/pricing-cards.tsx.template +115 -0
- package/dist/integrations/stripe/templates/web/src/pages/pricing.tsx.template +95 -0
- package/dist/templates/api/fastify/.env.example.template +7 -0
- package/dist/templates/api/fastify/.gitignore.template +24 -0
- package/dist/templates/api/fastify/package.json.template +23 -0
- package/dist/templates/api/fastify/src/index.ts.template +52 -0
- package/dist/templates/api/fastify/src/lib/env.ts.template +20 -0
- package/dist/templates/api/fastify/src/routes/health.ts.template +12 -0
- package/dist/templates/api/fastify/tsconfig.json.template +18 -0
- package/dist/templates/api/fastify-postgres/.env.example.template +10 -0
- package/dist/templates/api/fastify-postgres/drizzle.config.ts.template +10 -0
- package/dist/templates/api/fastify-postgres/package.json.template +16 -0
- package/dist/templates/api/fastify-postgres/src/db/index.ts.template +9 -0
- package/dist/templates/api/fastify-postgres/src/db/schema/users.ts.template +12 -0
- package/dist/templates/api/fastify-sqlite/.env.example.template +10 -0
- package/dist/templates/api/fastify-sqlite/drizzle.config.ts.template +10 -0
- package/dist/templates/api/fastify-sqlite/package.json.template +16 -0
- package/dist/templates/api/fastify-sqlite/src/db/index.ts.template +6 -0
- package/dist/templates/api/fastify-sqlite/src/db/schema/users.ts.template +12 -0
- package/dist/templates/api/fastify-supabase/.env.example.template +10 -0
- package/dist/templates/api/fastify-supabase/drizzle.config.ts.template +10 -0
- package/dist/templates/api/fastify-supabase/package.json.template +15 -0
- package/dist/templates/api/fastify-supabase/src/db/index.ts.template +9 -0
- package/dist/templates/api/fastify-supabase/src/db/schema/users.ts.template +12 -0
- package/dist/templates/api/fastify-turso/.env.example.template +11 -0
- package/dist/templates/api/fastify-turso/drizzle.config.ts.template +11 -0
- package/dist/templates/api/fastify-turso/package.json.template +15 -0
- package/dist/templates/api/fastify-turso/src/db/index.ts.template +10 -0
- package/dist/templates/api/fastify-turso/src/db/schema/users.ts.template +12 -0
- package/dist/templates/fullstack/api/.env.example.template +10 -0
- package/dist/templates/fullstack/api/.gitignore.template +4 -0
- package/dist/templates/fullstack/api/drizzle.config.ts.template +14 -0
- package/dist/templates/fullstack/api/package.json.template +33 -0
- package/dist/templates/fullstack/api/src/db/index.ts.template +13 -0
- package/dist/templates/fullstack/api/src/db/schema/api-keys.ts.template +19 -0
- package/dist/templates/fullstack/api/src/db/schema/audit-logs.ts.template +23 -0
- package/dist/templates/fullstack/api/src/db/schema/index.ts.template +8 -0
- package/dist/templates/fullstack/api/src/db/schema/invites.ts.template +19 -0
- package/dist/templates/fullstack/api/src/db/schema/memberships.ts.template +16 -0
- package/dist/templates/fullstack/api/src/db/schema/organizations.ts.template +13 -0
- package/dist/templates/fullstack/api/src/db/schema/plans.ts.template +29 -0
- package/dist/templates/fullstack/api/src/db/schema/subscriptions.ts.template +38 -0
- package/dist/templates/fullstack/api/src/db/schema/users.ts.template +14 -0
- package/dist/templates/fullstack/api/src/index.ts.template +54 -0
- package/dist/templates/fullstack/api/src/lib/env.ts.template +22 -0
- package/dist/templates/fullstack/api/src/routes/health.ts.template +14 -0
- package/dist/templates/fullstack/api/tsconfig.json.template +15 -0
- package/dist/templates/fullstack/root/.gitignore.template +26 -0
- package/dist/templates/fullstack/root/package.json.template +15 -0
- package/dist/templates/fullstack/root/pnpm-workspace.yaml.template +3 -0
- package/dist/templates/fullstack/root/turbo.json.template +17 -0
- package/dist/templates/fullstack/shared/package.json.template +36 -0
- package/dist/templates/fullstack/shared/src/index.ts.template +8 -0
- package/dist/templates/fullstack/shared/src/schemas/api-key.ts.template +28 -0
- package/dist/templates/fullstack/shared/src/schemas/audit-log.ts.template +41 -0
- package/dist/templates/fullstack/shared/src/schemas/index.ts.template +8 -0
- package/dist/templates/fullstack/shared/src/schemas/invite.ts.template +25 -0
- package/dist/templates/fullstack/shared/src/schemas/membership.ts.template +20 -0
- package/dist/templates/fullstack/shared/src/schemas/organization.ts.template +18 -0
- package/dist/templates/fullstack/shared/src/schemas/plan.ts.template +38 -0
- package/dist/templates/fullstack/shared/src/schemas/subscription.ts.template +56 -0
- package/dist/templates/fullstack/shared/src/schemas/user.ts.template +21 -0
- package/dist/templates/fullstack/shared/src/types/index.ts.template +75 -0
- package/dist/templates/fullstack/shared/src/validators/index.ts.template +53 -0
- package/dist/templates/fullstack/shared/tsconfig.json.template +17 -0
- package/dist/templates/fullstack/web/.gitignore.template +3 -0
- package/dist/templates/fullstack/web/index.html.template +13 -0
- package/dist/templates/fullstack/web/package.json.template +23 -0
- package/dist/templates/fullstack/web/src/App.tsx.template +47 -0
- package/dist/templates/fullstack/web/src/index.css.template +54 -0
- package/dist/templates/fullstack/web/src/main.tsx.template +10 -0
- package/dist/templates/fullstack/web/src/vite-env.d.ts.template +1 -0
- package/dist/templates/fullstack/web/tsconfig.json.template +21 -0
- package/dist/templates/fullstack/web/tsconfig.node.json.template +11 -0
- package/dist/templates/fullstack/web/vite.config.ts.template +15 -0
- package/dist/templates/hosted/root/.env.local.template +13 -0
- package/dist/templates/hosted/root/.gitignore.template +32 -0
- package/dist/templates/hosted/root/CLAUDE.md.template +139 -0
- package/dist/templates/hosted/root/drizzle.config.ts.template +10 -0
- package/dist/templates/hosted/root/next.config.ts.template +15 -0
- package/dist/templates/hosted/root/package.json.template +40 -0
- package/dist/templates/hosted/root/postcss.config.mjs.template +9 -0
- package/dist/templates/hosted/root/primstack.config.json.template +5 -0
- package/dist/templates/hosted/root/tailwind.config.ts.template +14 -0
- package/dist/templates/hosted/root/tsconfig.json.template +25 -0
- package/dist/templates/hosted/root/wrangler.toml.template +9 -0
- package/dist/templates/hosted/src/app/actions/example.ts.template +50 -0
- package/dist/templates/hosted/src/app/api/health/route.ts.template +5 -0
- package/dist/templates/hosted/src/app/auth/login/page.tsx.template +32 -0
- package/dist/templates/hosted/src/app/globals.css.template +59 -0
- package/dist/templates/hosted/src/app/layout.tsx.template +24 -0
- package/dist/templates/hosted/src/app/page.tsx.template +34 -0
- package/dist/templates/hosted/src/db/migrations/0000_initial.sql.template +43 -0
- package/dist/templates/hosted/src/db/schema.ts.template +52 -0
- package/dist/templates/hosted/src/env.d.ts.template +10 -0
- package/dist/templates/hosted/src/instrumentation.ts.template +6 -0
- package/dist/templates/hosted/src/lib/auth.ts.template +35 -0
- package/dist/templates/hosted/src/lib/db.ts.template +17 -0
- package/dist/templates/hosted/src/middleware.ts.template +6 -0
- package/package.json +46 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { {{DRIZZLE_IMPORTS}} } from 'drizzle-orm/pg-core';
|
|
2
|
+
{{REFERENCE_IMPORTS}}
|
|
3
|
+
|
|
4
|
+
export const {{ENTITY_PLURAL}} = pgTable('{{TABLE_NAME}}', {
|
|
5
|
+
id: uuid('id').primaryKey().defaultRandom(),
|
|
6
|
+
{{COLUMN_DEFINITIONS}}
|
|
7
|
+
createdAt: timestamp('created_at').notNull().defaultNow(),
|
|
8
|
+
updatedAt: timestamp('updated_at').notNull().defaultNow(),
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export type {{ENTITY_PASCAL}} = typeof {{ENTITY_PLURAL}}.$inferSelect;
|
|
12
|
+
export type New{{ENTITY_PASCAL}} = typeof {{ENTITY_PLURAL}}.$inferInsert;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { FastifyRequest, FastifyReply } from 'fastify';
|
|
2
|
+
import { eq } from 'drizzle-orm';
|
|
3
|
+
import { ZodError, z } from 'zod';
|
|
4
|
+
import { db } from '../../db/index.js';
|
|
5
|
+
import { {{ENTITY_PLURAL}}, type New{{ENTITY_PASCAL}} } from '../../db/schema/{{ENTITY}}.js';
|
|
6
|
+
import {
|
|
7
|
+
create{{ENTITY_PASCAL}}Schema,
|
|
8
|
+
update{{ENTITY_PASCAL}}Schema,
|
|
9
|
+
} from '{{SCHEMA_IMPORT_PATH}}';
|
|
10
|
+
import type {
|
|
11
|
+
Create{{ENTITY_PASCAL}},
|
|
12
|
+
Update{{ENTITY_PASCAL}},
|
|
13
|
+
} from '{{SCHEMA_IMPORT_PATH}}';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* List all {{ENTITY_PLURAL}}
|
|
17
|
+
*/
|
|
18
|
+
export async function list(_request: FastifyRequest, reply: FastifyReply) {
|
|
19
|
+
const result = await db.select().from({{ENTITY_PLURAL}});
|
|
20
|
+
return reply.send(result);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Get {{ENTITY}} by ID
|
|
25
|
+
*/
|
|
26
|
+
export async function getById(
|
|
27
|
+
request: FastifyRequest<{ Params: { id: string } }>,
|
|
28
|
+
reply: FastifyReply
|
|
29
|
+
) {
|
|
30
|
+
const { id } = request.params;
|
|
31
|
+
|
|
32
|
+
const parsedId = z.string().uuid().safeParse(id);
|
|
33
|
+
if (!parsedId.success) {
|
|
34
|
+
return reply.status(400).send({ error: 'Invalid id' });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const result = await db
|
|
38
|
+
.select()
|
|
39
|
+
.from({{ENTITY_PLURAL}})
|
|
40
|
+
.where(eq({{ENTITY_PLURAL}}.id, parsedId.data))
|
|
41
|
+
.limit(1);
|
|
42
|
+
|
|
43
|
+
if (result.length === 0) {
|
|
44
|
+
return reply.status(404).send({ error: '{{ENTITY_PASCAL}} not found' });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return reply.send(result[0]);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Create {{ENTITY}}
|
|
52
|
+
*/
|
|
53
|
+
export async function create(
|
|
54
|
+
request: FastifyRequest,
|
|
55
|
+
reply: FastifyReply
|
|
56
|
+
) {
|
|
57
|
+
let data: Create{{ENTITY_PASCAL}};
|
|
58
|
+
try {
|
|
59
|
+
data = create{{ENTITY_PASCAL}}Schema.parse(request.body);
|
|
60
|
+
} catch (err) {
|
|
61
|
+
if (err instanceof ZodError) {
|
|
62
|
+
return reply.status(400).send({ error: 'Invalid request body', details: err.flatten() });
|
|
63
|
+
}
|
|
64
|
+
throw err;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const result = await db
|
|
68
|
+
.insert({{ENTITY_PLURAL}})
|
|
69
|
+
.values(data as New{{ENTITY_PASCAL}})
|
|
70
|
+
.returning();
|
|
71
|
+
|
|
72
|
+
return reply.status(201).send(result[0]);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Update {{ENTITY}}
|
|
77
|
+
*/
|
|
78
|
+
export async function update(
|
|
79
|
+
request: FastifyRequest<{ Params: { id: string } }>,
|
|
80
|
+
reply: FastifyReply
|
|
81
|
+
) {
|
|
82
|
+
const { id } = request.params;
|
|
83
|
+
|
|
84
|
+
const parsedId = z.string().uuid().safeParse(id);
|
|
85
|
+
if (!parsedId.success) {
|
|
86
|
+
return reply.status(400).send({ error: 'Invalid id' });
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
let data: Update{{ENTITY_PASCAL}};
|
|
90
|
+
try {
|
|
91
|
+
data = update{{ENTITY_PASCAL}}Schema.parse(request.body);
|
|
92
|
+
} catch (err) {
|
|
93
|
+
if (err instanceof ZodError) {
|
|
94
|
+
return reply.status(400).send({ error: 'Invalid request body', details: err.flatten() });
|
|
95
|
+
}
|
|
96
|
+
throw err;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const result = await db
|
|
100
|
+
.update({{ENTITY_PLURAL}})
|
|
101
|
+
.set(data as Partial<New{{ENTITY_PASCAL}}>)
|
|
102
|
+
.where(eq({{ENTITY_PLURAL}}.id, parsedId.data))
|
|
103
|
+
.returning();
|
|
104
|
+
|
|
105
|
+
if (result.length === 0) {
|
|
106
|
+
return reply.status(404).send({ error: '{{ENTITY_PASCAL}} not found' });
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return reply.send(result[0]);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Delete {{ENTITY}}
|
|
114
|
+
*/
|
|
115
|
+
export async function remove(
|
|
116
|
+
request: FastifyRequest<{ Params: { id: string } }>,
|
|
117
|
+
reply: FastifyReply
|
|
118
|
+
) {
|
|
119
|
+
const { id } = request.params;
|
|
120
|
+
|
|
121
|
+
const parsedId = z.string().uuid().safeParse(id);
|
|
122
|
+
if (!parsedId.success) {
|
|
123
|
+
return reply.status(400).send({ error: 'Invalid id' });
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const result = await db
|
|
127
|
+
.delete({{ENTITY_PLURAL}})
|
|
128
|
+
.where(eq({{ENTITY_PLURAL}}.id, parsedId.data))
|
|
129
|
+
.returning();
|
|
130
|
+
|
|
131
|
+
if (result.length === 0) {
|
|
132
|
+
return reply.status(404).send({ error: '{{ENTITY_PASCAL}} not found' });
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return reply.status(204).send();
|
|
136
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { FastifyPluginAsync } from 'fastify';
|
|
2
|
+
import * as handlers from './handlers.js';
|
|
3
|
+
|
|
4
|
+
export const {{ENTITY_PLURAL}}Routes: FastifyPluginAsync = async (fastify) => {
|
|
5
|
+
// List all {{ENTITY_PLURAL}}
|
|
6
|
+
fastify.get('/', handlers.list);
|
|
7
|
+
|
|
8
|
+
// Get {{ENTITY}} by ID
|
|
9
|
+
fastify.get<{ Params: { id: string } }>('/:id', handlers.getById);
|
|
10
|
+
|
|
11
|
+
// Create {{ENTITY}}
|
|
12
|
+
fastify.post('/', handlers.create);
|
|
13
|
+
|
|
14
|
+
// Update {{ENTITY}}
|
|
15
|
+
fastify.patch<{ Params: { id: string } }>('/:id', handlers.update);
|
|
16
|
+
|
|
17
|
+
// Delete {{ENTITY}}
|
|
18
|
+
fastify.delete<{ Params: { id: string } }>('/:id', handlers.remove);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default {{ENTITY_PLURAL}}Routes;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
export const {{ENTITY}}Schema = z.object({
|
|
4
|
+
id: z.string().uuid(),
|
|
5
|
+
{{FIELD_SCHEMAS}}
|
|
6
|
+
createdAt: z.coerce.date(),
|
|
7
|
+
updatedAt: z.coerce.date(),
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export const create{{ENTITY_PASCAL}}Schema = {{ENTITY}}Schema.omit({
|
|
11
|
+
id: true,
|
|
12
|
+
createdAt: true,
|
|
13
|
+
updatedAt: true,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export const update{{ENTITY_PASCAL}}Schema = create{{ENTITY_PASCAL}}Schema.partial();
|
|
17
|
+
|
|
18
|
+
export type {{ENTITY_PASCAL}} = z.infer<typeof {{ENTITY}}Schema>;
|
|
19
|
+
export type Create{{ENTITY_PASCAL}} = z.infer<typeof create{{ENTITY_PASCAL}}Schema>;
|
|
20
|
+
export type Update{{ENTITY_PASCAL}} = z.infer<typeof update{{ENTITY_PASCAL}}Schema>;
|