feat(rewrite): Initial database and /inclusive endpoints code

#prisma: Instead of using `.prisma/client` and `@prisma/client` (which re-exports `.prisma/client`, the rewrite now just uses the generated code directly through `#prisma` (see package.json and tsconfig.json).
inclusive: The `/inclusive` endpoint has started to be written. Right now the code is untested as I don't have sample data, but I'll test it soon enough.
This commit is contained in:
tecc 2023-10-03 05:29:44 +02:00
parent 581d6e7da3
commit 887498daed
No known key found for this signature in database
GPG Key ID: 622EEC5BAE5EBD3A
5 changed files with 44 additions and 4 deletions

View File

@ -24,7 +24,6 @@
"keywords": [], "keywords": [],
"author": "", "author": "",
"dependencies": { "dependencies": {
".prisma/client": "link:prisma/dist",
"@fastify/type-provider-typebox": "^3.5.0", "@fastify/type-provider-typebox": "^3.5.0",
"@prisma/client": "5.3.1", "@prisma/client": "5.3.1",
"@pronounspage/common": "workspace:*", "@pronounspage/common": "workspace:*",
@ -44,6 +43,8 @@
"typescript": "^5.2.2" "typescript": "^5.2.2"
}, },
"imports": { "imports": {
"#self/*": "./dist/*.js" "#self/*": "./dist/*.js",
"#prisma": "./prisma/dist/index.js",
"#prisma/*": "./prisma/dist/*.js"
} }
} }

4
new/backend/src/db.ts Normal file
View File

@ -0,0 +1,4 @@
import { PrismaClient } from "#prisma";
export type * from "#prisma";
export const db = new PrismaClient();

View File

@ -2,12 +2,12 @@ import { Type } from "@sinclair/typebox";
import { import {
allPronounVariants, allPronounVariants,
examplesFor, examplesFor,
getLocale,
Locale, Locale,
Pronoun, Pronoun,
PronounExample, PronounExample,
} from "#self/locales"; } from "#self/locales";
import pronouns from "#self/server/v1/pronouns"; import pronouns from "#self/server/v1/pronouns";
import inclusive from "#self/server/v1/inclusive";
export type V1AppInstance = AppInstance; export type V1AppInstance = AppInstance;
@ -107,5 +107,6 @@ export function transformPronoun(
export const routes = async function (app: AppInstance) { export const routes = async function (app: AppInstance) {
app.register(pronouns); app.register(pronouns);
app.register(inclusive);
} satisfies AppPluginAsync; } satisfies AppPluginAsync;
export default routes; export default routes;

View File

@ -0,0 +1,33 @@
import { localeSpecific } from "#self/server/v1";
import { db, Inclusive } from "#self/db";
export function transformInclusive(inc: Inclusive) {
return {
id: inc.id,
insteadOf: inc.insteadOf,
say: inc.say,
because: inc.because,
locale: inc.locale,
};
}
export const plugin = async function (app) {
app.get(
"/:locale/inclusive",
{
schema: {
params: localeSpecific,
},
},
async (req, reply) => {
const values = await db.inclusive.findMany({
where: {
locale: req.params.locale,
},
take: 50,
});
return reply.send(values.map(transformInclusive));
}
);
} satisfies AppPluginAsync;
export default plugin;

View File

@ -9,7 +9,8 @@
"outDir": "./dist", "outDir": "./dist",
"resolvePackageJsonExports": true, "resolvePackageJsonExports": true,
"paths": { "paths": {
"#self/*": ["./src/*.js"] "#self/*": ["./src/*.js"],
"#prisma": ["./prisma/dist/index.d.ts"]
}, },
"incremental": true, "incremental": true,
"strictNullChecks": true, "strictNullChecks": true,