nicoalbanese / kirimase

Build full-stack Next.js apps, incredibly fast
https://kirimase.dev
MIT License
2.58k stars 118 forks source link

Generated model that belongs to user doesn't import userId type #2

Closed nelsonfrz closed 1 year ago

nelsonfrz commented 1 year ago

Config kirimase.config.json:

{
  "driver": "pg",
  "hasSrc": false,
  "provider": "postgresjs",
  "packages": [
    "drizzle",
    "trpc",
    "next-auth",
    "shadcn-ui"
  ],
  "preferredPackageManager": "npm"
}

Command:

$ npx kirimase@latest generate

ℹ Quickly generate your Model (Drizzle schema + queries / mutations), Controllers (API Routes and TRPC Routes), and Views                                                 7:47:09 PM
? Please select the resources you would like to generate: Model, API Route, TRPC Route, Views + Components (with Shadcn UI, requires TRPC route)
? Please enter the table name (plural and in snake_case): errors
? Please select the type of this field: boolean
? Please enter the field name (in snake_case): applied
? Is this field required? yes
? Would you like to add another field? no
? Would you like to set up an index? no
? Does this model belong to the user? yes
✔ File created at lib/db/schema/errors.ts                                                                                                                                 7:47:35 PM
✔ File created at lib/api/errors/queries.ts                                                                                                                               7:47:35 PM
✔ File created at lib/api/errors/mutations.ts                                                                                                                             7:47:35 PM
✔ File created at app/api/errors/route.ts                                                                                                                                 7:47:35 PM
✔ File created at lib/server/routers/errors.ts                                                                                                                            7:47:35 PM
✔ File replaced at lib/server/routers/_app.ts                                                                                                                             7:47:35 PM
✔ Added errors router to root router successfully.                                                                                                                        7:47:35 PM
✔ File created at app/errors/page.tsx                                                                                                                                     7:47:35 PM
✔ File created at components/errors/ErrorList.tsx                                                                                                                         7:47:35 PM
✔ File created at components/errors/ErrorForm.tsx                                                                                                                         7:47:35 PM
✔ File created at components/errors/ErrorModal.tsx                                                                                                                        7:47:35 PM
ℹ All items already installed.                                                                                                                                            7:47:35 PM

Model lib/db/schema/errors.ts:

Screenshot 2023-09-04 at 19 51 23
nicoalbanese commented 1 year ago

Hey Nelson! Thanks for spotting. Your fix was the right logic, but ended up creating a duplicate import if the string type was already being used by another field. I ended up using your code, but moving it up a few lines to the uniqueTypes declaration that removes duplicate values from the array. Thanks again!