aboutsummaryrefslogtreecommitdiff
path: root/pages/en/db-test.js
blob: f2dccd3d497abed553ba829217f4f130925abce7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { PrismaClient } from "@prisma/client";
import { useState } from "react";
const prisma = new PrismaClient();

export async function getServerSideProps() {
  const user = await prisma.user.findMany({
    where: {
      setting: {
        path: ["language"],
        equals: "id",
      },
    },
  });
  return {
    props: {
      user,
    },
  };
}

const settings = {
  isAdult: false,
  theme: "dark",
  language: "en",
};

export default function DbTest({ user }) {
  const [add, setUser] = useState();

  console.log(user);

  async function handleCreate(e) {
    e.preventDefault();
    const res = await fetch("/api/user", {
      method: "POST",
      body: JSON.stringify({ name: add, setting: settings }),
    });
    const json = await res.json();
    console.log(json);
  }
  //   console.log(add);
  return (
    <div>
      <form onSubmit={handleCreate}>
        <input type="text" onChange={(e) => setUser(e.target.value)} />
        <button type="submit">Submit</button>
      </form>
      <h1>hello gaes</h1>
    </div>
  );
}

const user = [
  {
    id: String,
    name: String,
    setting: {
      isAdult: Boolean,
      theme: String,
      language: String,
    },
    watchList: [
      {
        id: String,
        title: String,
        episodes: [
          {
            id: String,
            title: String,
            episode: Number,
            url: String,
            timeWatched: Number,
            duration: Number,
          },
        ],
      },
    ],
  },
];