Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

315
Views
How can I update a field in Prisma using Next.js

I want to update the tasks field using Prisma for my PlanetScale Database, how can I do that?

Here's the schema.prisma file code,

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["referentialIntegrity"]
}

datasource db {
  provider             = "mysql"
  url                  = env("DATABASE_URL")
  referentialIntegrity = "prisma"
}

model User{
  id      Int   @default(autoincrement()) @id
  uid         String @unique
  tasks       String @default("[]")
  createdAt   DateTime @default(now())
  secretKey   String @default(cuid()) @unique
}

And here is my Next.js API source code,

import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();

export default async function handler(req, res){
    if(req.method === 'POST'){
        return await createTask(req, res);
    }else{
        res.status(405).json({
            message: 'Method not allowed',
            success: false
        })
    }
}

async function createTask(req, res){
    const { userId } = req.body;
    try{
        const body = req.body;
        // update the user's task list
        const user = await prisma.user.update({
            where: {
                uid: userId
            },
            data: {
                tasks: body.value
            }
        })
        res.status(200).json({
            message: 'Task created',
            success: true
        })
    }catch (error) {
        console.error("Request error", error);
        res.status(500).json({ error: "Error creating tasks", success:false });
    }
}

Please guide me to resolve this problem

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!