Skip to content

Commit

Permalink
fix: Fixed errors in SST and database configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
JulioEmmmanuel committed Jun 6, 2024
1 parent c7ad837 commit 5943291
Show file tree
Hide file tree
Showing 40 changed files with 3,665 additions and 1,889 deletions.
41 changes: 24 additions & 17 deletions src/app/api/healthdata/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export async function POST(request: Request) {

// Now, proceed with updating or creating userDetail
const { sex, weight, height, bodyFat, muscularMass, birthDate } = body
console.log('aca ando')

const detail = await db
.select()
.from(userDetail)
Expand All @@ -76,36 +76,43 @@ export async function POST(request: Request) {
.where(eq(userDetail.idUser, session.user?.id))
} else {
// Create userDetail
res = await db.insert(userDetail).values({

const insertData: {
sex: string
idUser: number
weight: number
height: number
bodyFat?: number
muscularMass?: number
birthDate: Date
} = {
idUser: session.user?.id,
sex: sex,
weight: Number(weight),
height: Number(height),
bodyFat: Number(bodyFat),
muscularMass: Number(muscularMass),
birthDate: new Date(birthDate),
})
console.log(res)

// If phoneNumber is provided, update it in the User table
if (phoneNumber) {
await db
.update(user)
.set({
phoneNumber: phoneNumber,
})
.where(eq(user.idUser, session.user?.id))
}

const medical = await db.insert(medicalProfile).values({
if (bodyFat) {
insertData.bodyFat = Number(bodyFat)
}

if (muscularMass) {
insertData.muscularMass = Number(muscularMass)
}

console.log(insertData)

res = await db.insert(userDetail).values(insertData)

await db.insert(medicalProfile).values({
idUser: session.user?.id,
emergencyName: null,
emergencyPhone: null,
policyUser: null,
insuranceCompany: null,
bloodType: null,
})
console.log(medical)
}
return NextResponse.json(res, { status: 200 })
} catch (error) {
Expand Down
10 changes: 5 additions & 5 deletions src/app/api/membership/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { user } from '@/src/db/schema/schema'
import { db } from '@/src/db/drizzle'

export async function GET() {
try {
const session = await getServerSession(authOptions)
const session = await getServerSession(authOptions)

if (!session) {
return NextResponse.json({ message: 'Unauthorized' }, { status: 401 })
}
if (!session) {
return NextResponse.json({ message: 'Unauthorized' }, { status: 401 })
}

try {
const res = await db
.select()
.from(user)
Expand Down
10 changes: 5 additions & 5 deletions src/app/api/post/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { db } from '@/src/db/drizzle'
import { sql } from 'drizzle-orm/sql'

export async function GET() {
try {
const session = await getServerSession(authOptions)
const session = await getServerSession(authOptions)

if (!session) {
return NextResponse.json({ message: 'Unauthorized' }, { status: 401 })
}
if (!session) {
return NextResponse.json({ message: 'Unauthorized' }, { status: 401 })
}

try {
const res = await db
.select({
idPost: posts.idPost,
Expand Down
10 changes: 5 additions & 5 deletions src/app/api/post/user/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { db } from '@/src/db/drizzle'
import { user } from '@/src/db/schema/schema'

export async function GET() {
try {
const session = await getServerSession(authOptions)
const session = await getServerSession(authOptions)

if (!session) {
return NextResponse.json('Unauthorized', { status: 401 })
}
if (!session) {
return NextResponse.json('Unauthorized', { status: 401 })
}

try {
const res = await db
.select()
.from(user)
Expand Down
10 changes: 5 additions & 5 deletions src/app/api/profile/userData/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { medicalProfile } from '@/src/db/schema/schema'
import { db } from '@/src/db/drizzle'

export async function GET() {
try {
const session = await getServerSession(authOptions)
const session = await getServerSession(authOptions)

if (!session) {
return NextResponse.json('Unauthorized', { status: 401 })
}
if (!session) {
return NextResponse.json('Unauthorized', { status: 401 })
}

try {
const detail = await db
.select()
.from(medicalProfile)
Expand Down
10 changes: 5 additions & 5 deletions src/app/api/ranking/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { userPoints, user } from '@/src/db/schema/schema'
import { eq, desc } from 'drizzle-orm'

export async function GET() {
try {
const session = await getServerSession(authOptions)
const session = await getServerSession(authOptions)

if (!session) {
return NextResponse.json({ message: 'Unauthorized' }, { status: 401 })
}
if (!session) {
return NextResponse.json({ message: 'Unauthorized' }, { status: 401 })
}

try {
const res = await db
.select({
idUser: user.idUser,
Expand Down
10 changes: 5 additions & 5 deletions src/app/api/records/sleep/last/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { getServerSession } from 'next-auth'
import { NextResponse } from 'next/server'

export async function GET() {
try {
const session = await getServerSession(authOptions)
const session = await getServerSession(authOptions)

if (!session) {
return NextResponse.json('Unauthorized', { status: 401 })
}
if (!session) {
return NextResponse.json('Unauthorized', { status: 401 })
}

try {
const res = await db
.select()
.from(record)
Expand Down
10 changes: 5 additions & 5 deletions src/app/api/records/sleep/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { getServerSession } from 'next-auth'
import { NextResponse } from 'next/server'

export async function GET() {
try {
const session = await getServerSession(authOptions)
const session = await getServerSession(authOptions)

if (!session) {
return NextResponse.json('Unauthorized', { status: 401 })
}
if (!session) {
return NextResponse.json('Unauthorized', { status: 401 })
}

try {
//get data from the last 7 days
const res = await db
.select({
Expand Down
5 changes: 3 additions & 2 deletions src/app/api/stripe/payment/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { authOptions } from '@/src/lib/auth/authOptions'
import config from '@/src/lib/environment/config'
import { stripe } from '@/src/lib/stripe/stripe'
import { getServerSession } from 'next-auth'
import { NextResponse } from 'next/server'
Expand All @@ -10,8 +11,8 @@ export async function POST(req: Request) {
const { priceId, allowTrial } = body

const stripeConfig: Stripe.Checkout.SessionCreateParams = {
success_url: 'http://localhost:3000/home',
cancel_url: 'http://localhost:3000',
success_url: config.nextAuthUrl + '/home',
cancel_url: config.nextAuthUrl,
payment_method_types: ['card'],
mode: 'subscription',
billing_address_collection: 'auto',
Expand Down
2 changes: 2 additions & 0 deletions src/db/migrations/0027_fat_muscular_nullable.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE "UserDetail" ALTER COLUMN "body_fat" DROP NOT NULL;--> statement-breakpoint
ALTER TABLE "UserDetail" ALTER COLUMN "muscular_mass" DROP NOT NULL;
50 changes: 25 additions & 25 deletions src/db/migrations/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"id": "7fb4f41d-f861-46e4-91b9-65c5c4c826e0",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "5",
"dialect": "pg",
"version": "7",
"dialect": "postgresql",
"tables": {
"PortionsNutrition": {
"public.PortionsNutrition": {
"name": "PortionsNutrition",
"schema": "",
"columns": {
Expand Down Expand Up @@ -74,29 +72,29 @@
"PortionsNutrition_id_user_User_id_user_fk": {
"name": "PortionsNutrition_id_user_User_id_user_fk",
"tableFrom": "PortionsNutrition",
"tableTo": "User",
"columnsFrom": [
"id_user"
],
"tableTo": "User",
"columnsTo": [
"id_user"
],
"onDelete": "restrict",
"onUpdate": "cascade"
"onUpdate": "cascade",
"onDelete": "restrict"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"PortionsNutrition_id_user_unique": {
"name": "PortionsNutrition_id_user_unique",
"nullsNotDistinct": false,
"columns": [
"id_user"
]
],
"nullsNotDistinct": false
}
}
},
"_prisma_migrations": {
"public._prisma_migrations": {
"name": "_prisma_migrations",
"schema": "",
"columns": {
Expand Down Expand Up @@ -156,7 +154,7 @@
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"User": {
"public.User": {
"name": "User",
"schema": "",
"columns": {
Expand Down Expand Up @@ -197,21 +195,21 @@
"uniqueConstraints": {
"User_email_unique": {
"name": "User_email_unique",
"nullsNotDistinct": false,
"columns": [
"email"
]
],
"nullsNotDistinct": false
},
"User_phone_number_unique": {
"name": "User_phone_number_unique",
"nullsNotDistinct": false,
"columns": [
"phone_number"
]
],
"nullsNotDistinct": false
}
}
},
"UserDetail": {
"public.UserDetail": {
"name": "UserDetail",
"schema": "",
"columns": {
Expand Down Expand Up @@ -269,34 +267,36 @@
"UserDetail_id_user_User_id_user_fk": {
"name": "UserDetail_id_user_User_id_user_fk",
"tableFrom": "UserDetail",
"tableTo": "User",
"columnsFrom": [
"id_user"
],
"tableTo": "User",
"columnsTo": [
"id_user"
],
"onDelete": "restrict",
"onUpdate": "cascade"
"onUpdate": "cascade",
"onDelete": "restrict"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"UserDetail_id_user_unique": {
"name": "UserDetail_id_user_unique",
"nullsNotDistinct": false,
"columns": [
"id_user"
]
],
"nullsNotDistinct": false
}
}
}
},
"enums": {},
"schemas": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
"tables": {},
"columns": {}
},
"id": "7fb4f41d-f861-46e4-91b9-65c5c4c826e0",
"prevId": "00000000-0000-0000-0000-000000000000"
}
Loading

0 comments on commit 5943291

Please sign in to comment.