conniehunt
conniehunt
Explore posts from servers
PPrisma
Created by conniehunt on 7/6/2024 in #help-and-questions
NestJS + prisma
Giving nestjs and prisma a go together for the first time but can't get it to run a migration or db push
// app.module.ts
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { SurveysModule } from './surveys/surveys.module';
import { UsersModule } from './users/users.module';
import { IntegrationsModule } from './integrations/integrations.module';
import { DatabaseModule } from './database/database.module';
import { StripeModule } from './stripe/stripe.module';
import { ConfigModule } from '@nestjs/config';
import { PrismaService } from './prisma.service';

@Module({
imports: [
SurveysModule,
UsersModule,
IntegrationsModule,
DatabaseModule,
StripeModule,
ConfigModule.forRoot({
isGlobal: true,
}),
],
controllers: [AppController],
providers: [AppService, PrismaService],
})
export class AppModule {}
// app.module.ts
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { SurveysModule } from './surveys/surveys.module';
import { UsersModule } from './users/users.module';
import { IntegrationsModule } from './integrations/integrations.module';
import { DatabaseModule } from './database/database.module';
import { StripeModule } from './stripe/stripe.module';
import { ConfigModule } from '@nestjs/config';
import { PrismaService } from './prisma.service';

@Module({
imports: [
SurveysModule,
UsersModule,
IntegrationsModule,
DatabaseModule,
StripeModule,
ConfigModule.forRoot({
isGlobal: true,
}),
],
controllers: [AppController],
providers: [AppService, PrismaService],
})
export class AppModule {}
//prisma.service.ts
import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';

@Injectable()
export class PrismaService
extends PrismaClient
implements OnModuleInit, OnModuleDestroy
{
async onModuleInit() {
await this.$connect();
}

async onModuleDestroy() {
await this.$disconnect();
}
}
//prisma.service.ts
import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';

@Injectable()
export class PrismaService
extends PrismaClient
implements OnModuleInit, OnModuleDestroy
{
async onModuleInit() {
await this.$connect();
}

async onModuleDestroy() {
await this.$disconnect();
}
}
//schema
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model User {
id String @id
clerkId String @unique
emailAddress String? @unique
createdAt DateTime @default(now())
firstName String?
lastName String?
fullName String? @map("firstName + ' ' + lastName")
updatedAt DateTime? @updatedAt

@@index(clerkId)
}
//schema
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model User {
id String @id
clerkId String @unique
emailAddress String? @unique
createdAt DateTime @default(now())
firstName String?
lastName String?
fullName String? @map("firstName + ' ' + lastName")
updatedAt DateTime? @updatedAt

@@index(clerkId)
}
when I run npx prisma migrate dev or npx prisma db push the process just freezes
3 replies
TTCTheo's Typesafe Cult
Created by conniehunt on 9/8/2023 in #questions
T3env: Module not found: Can't resolve '@/env.mjs'
Hi, I am trying to use T3env for the first time but i keep getting this error in build Module not found: Can't resolve '@/env.mjs'. My env.mjs is in my src folder. here is my env.mjs file:
import { createEnv } from '@t3-oss/env-nextjs';
import { z } from 'zod';

export const env = createEnv({
server: {
DATABASE_URL: z.string().url(),
OPEN_AI_API_KEY: z.string().min(1),
OPEN_AI_ORGANIZATION_ID: z.string().min(1),
BITLY_ACCESS_TOKEN: z.string().min(1),
PASSWORD: z.string().min(1),
CLERK_SECRET_KEY: z.string().min(1),
WEBHOOK_SECRET: z.string().min(1),
RESEND_API_KEY: z.string().min(1),
},
client: {
NEXT_PUBLIC_LOCAL_URL: z.string().url(),
NEXT_PUBLIC_VERCEL_URL: z.string().url(),
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: z.string().min(1),
},
experimental__runtimeEnv: {
NEXT_PUBLIC_LOCAL_URL: process.env.NEXT_PUBLIC_LOCAL_URL,
NEXT_PUBLIC_VERCEL_URL: process.env.NEXT_PUBLIC_VERCEL_URL,
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY:
process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY,
},
});
import { createEnv } from '@t3-oss/env-nextjs';
import { z } from 'zod';

export const env = createEnv({
server: {
DATABASE_URL: z.string().url(),
OPEN_AI_API_KEY: z.string().min(1),
OPEN_AI_ORGANIZATION_ID: z.string().min(1),
BITLY_ACCESS_TOKEN: z.string().min(1),
PASSWORD: z.string().min(1),
CLERK_SECRET_KEY: z.string().min(1),
WEBHOOK_SECRET: z.string().min(1),
RESEND_API_KEY: z.string().min(1),
},
client: {
NEXT_PUBLIC_LOCAL_URL: z.string().url(),
NEXT_PUBLIC_VERCEL_URL: z.string().url(),
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: z.string().min(1),
},
experimental__runtimeEnv: {
NEXT_PUBLIC_LOCAL_URL: process.env.NEXT_PUBLIC_LOCAL_URL,
NEXT_PUBLIC_VERCEL_URL: process.env.NEXT_PUBLIC_VERCEL_URL,
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY:
process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY,
},
});
Very confused, since ive followed the documentation exactly aside from including import "./src/env.mjs"; in my next.config.js since I can't use imports outside of a module
2 replies
TTCTheo's Typesafe Cult
Created by conniehunt on 5/27/2023 in #questions
NextJS(13) API call cache MISS
10 replies
TTCTheo's Typesafe Cult
Created by conniehunt on 5/21/2023 in #questions
API route call from another API route
hoping someone can help me here. Below is my NextJs(v13 app dir) Api route which Stripe forwards webhooks to, when the event.type of "checkout.session.completed" is sent i want to call another API route (add-credits).
import { NextResponse } from 'next/server';
import { buffer } from 'node:stream/consumers';
import { stripe } from '~/lib/stripe';

export async function POST(req: any) {
const rawBody = await buffer(req.body);
let event;
try {
event = stripe.webhooks.constructEvent(
rawBody,
req.headers.get('stripe-signature') as string,
process.env.STRIPE_WEBHOOK_SIGNING_SECRET as string
);
} catch (err) {
console.log(err);
return NextResponse.json(
{
message: 'Webhook signature verification failed',
},
{
status: 400,
}
);
}

switch (event.type) {
case 'checkout.session.completed':
await fetch('http://localhost:3000/api/clerk/add-credits', {
method: 'GET',
});

break;
default:
console.log(`Unhandled event type ${event.type}`);
}

// have to return response promptly, ie without waiting for back-end process or stripe will potentially flag your account
return NextResponse.json(
{ message: 'successfully received' },
{ status: 200 }
);
}
import { NextResponse } from 'next/server';
import { buffer } from 'node:stream/consumers';
import { stripe } from '~/lib/stripe';

export async function POST(req: any) {
const rawBody = await buffer(req.body);
let event;
try {
event = stripe.webhooks.constructEvent(
rawBody,
req.headers.get('stripe-signature') as string,
process.env.STRIPE_WEBHOOK_SIGNING_SECRET as string
);
} catch (err) {
console.log(err);
return NextResponse.json(
{
message: 'Webhook signature verification failed',
},
{
status: 400,
}
);
}

switch (event.type) {
case 'checkout.session.completed':
await fetch('http://localhost:3000/api/clerk/add-credits', {
method: 'GET',
});

break;
default:
console.log(`Unhandled event type ${event.type}`);
}

// have to return response promptly, ie without waiting for back-end process or stripe will potentially flag your account
return NextResponse.json(
{ message: 'successfully received' },
{ status: 200 }
);
}
When the call to add-credits route is made i get status code 200 but it says (MISS) in console
2 replies