diff --git a/app/migrations/0007_chilly_arachne.sql b/app/migrations/0007_chilly_arachne.sql new file mode 100644 index 0000000..1e467fb --- /dev/null +++ b/app/migrations/0007_chilly_arachne.sql @@ -0,0 +1 @@ +ALTER TABLE "transcriptions" ADD COLUMN "user_name" text; \ No newline at end of file diff --git a/app/migrations/meta/0007_snapshot.json b/app/migrations/meta/0007_snapshot.json new file mode 100644 index 0000000..2a5c1c7 --- /dev/null +++ b/app/migrations/meta/0007_snapshot.json @@ -0,0 +1,248 @@ +{ + "id": "1b89f5e6-7610-4b18-9af0-cb69c39c67c2", + "prevId": "da5e1ba2-42b5-4c56-9a01-83ef8cd77a95", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.registrations": { + "name": "registrations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "userName": { + "name": "userName", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "userEmail": { + "name": "userEmail", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.session": { + "name": "session", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "session_user_id_user_id_fk": { + "name": "session_user_id_user_id_fk", + "tableFrom": "session", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.transcriptions": { + "name": "transcriptions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "translation": { + "name": "translation", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "summary": { + "name": "summary", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "documentUrl": { + "name": "documentUrl", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "documentName": { + "name": "documentName", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "isDefault": { + "name": "isDefault", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "audioDuration": { + "name": "audioDuration", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "user_name": { + "name": "user_name", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "transcriptions_user_id_user_id_fk": { + "name": "transcriptions_user_id_user_id_fk", + "tableFrom": "transcriptions", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.user": { + "name": "user", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "password_hash": { + "name": "password_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "contactNumber": { + "name": "contactNumber", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "user_username_unique": { + "name": "user_username_unique", + "nullsNotDistinct": false, + "columns": [ + "username" + ] + } + } + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/app/migrations/meta/_journal.json b/app/migrations/meta/_journal.json index f2bbe36..c202f1f 100644 --- a/app/migrations/meta/_journal.json +++ b/app/migrations/meta/_journal.json @@ -50,6 +50,13 @@ "when": 1732709159106, "tag": "0006_stormy_rocket_racer", "breakpoints": true + }, + { + "idx": 7, + "version": "7", + "when": 1732817602505, + "tag": "0007_chilly_arachne", + "breakpoints": true } ] } \ No newline at end of file diff --git a/app/src/app/api/transcribe/save/route.ts b/app/src/app/api/transcribe/save/route.ts index 23c9848..d47c809 100644 --- a/app/src/app/api/transcribe/save/route.ts +++ b/app/src/app/api/transcribe/save/route.ts @@ -1,5 +1,6 @@ import { db } from "@/db"; -import { transcriptions, TranscriptionsPayload } from "@/db/schema"; +import { transcriptions, TranscriptionsPayload, userTable } from "@/db/schema"; +import { eq } from "drizzle-orm"; export async function POST(req: Request) { try { @@ -10,16 +11,31 @@ export async function POST(req: Request) { documentName, summary, translation, - audioDuration + audioDuration, }: TranscriptionsPayload = body; + const userResponse = await db + .select({ + userName: userTable.name + }) + .from(userTable) + .where(eq(userTable.id, userID)) + + if (!userResponse[0]) { + return new Response("User not found", { + status: 404, + }) + } + + const response = await db.insert(transcriptions).values({ documentUrl, documentName, userID, summary, translation, - audioDuration + audioDuration, + userName: userResponse[0].userName }).returning(); return new Response(JSON.stringify(response), { status: 200 }); diff --git a/app/src/db/schema.ts b/app/src/db/schema.ts index da7ca8e..44d95c2 100644 --- a/app/src/db/schema.ts +++ b/app/src/db/schema.ts @@ -11,7 +11,8 @@ export const transcriptions = pgTable("transcriptions", { documentUrl: text("documentUrl").notNull(), documentName: text("documentName").notNull(), isDefault: boolean("isDefault").notNull().default(false), - audioDuration: integer("audioDuration") + audioDuration: integer("audioDuration"), + userName: text("user_name") }); export const registrations = pgTable("registrations", {