Skip to content

Commit

Permalink
Merge pull request #58 from joshsoftware/chore/user_name_field
Browse files Browse the repository at this point in the history
chore: user_name column for powerbi
  • Loading branch information
AjinkyaASK authored Nov 29, 2024
2 parents 9f4ec38 + 55f778f commit 18e103b
Show file tree
Hide file tree
Showing 5 changed files with 277 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/migrations/0007_chilly_arachne.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "transcriptions" ADD COLUMN "user_name" text;
248 changes: 248 additions & 0 deletions app/migrations/meta/0007_snapshot.json
Original file line number Diff line number Diff line change
@@ -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": {}
}
}
7 changes: 7 additions & 0 deletions app/migrations/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
22 changes: 19 additions & 3 deletions app/src/app/api/transcribe/save/route.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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 });
Expand Down
3 changes: 2 additions & 1 deletion app/src/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down

0 comments on commit 18e103b

Please sign in to comment.