mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-09-24 05:05:20 -04:00
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:
parent
581d6e7da3
commit
887498daed
@ -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
4
new/backend/src/db.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import { PrismaClient } from "#prisma";
|
||||||
|
export type * from "#prisma";
|
||||||
|
|
||||||
|
export const db = new PrismaClient();
|
@ -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;
|
||||||
|
33
new/backend/src/server/v1/inclusive.ts
Normal file
33
new/backend/src/server/v1/inclusive.ts
Normal 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;
|
@ -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,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user