This commit is contained in:
Andreas Schaafsma 2023-06-11 05:12:38 +02:00
parent 6b847910b7
commit 01960771f4
2 changed files with 24 additions and 7 deletions

View File

@ -1,5 +1,13 @@
import Gens from "@/gens";
import { Sequelize, DataTypes } from 'sequelize';
const sequelize = new Sequelize('sqlite::memory:');
const MPost = sequelize.define('Post', {
id: DataTypes.INTEGER,
title: DataTypes.STRING,
content: DataTypes.STRING,
date: DataTypes.DATE,
});
export type Post = {
id: Number,

View File

@ -2,13 +2,22 @@ import mysql2, { Connection, RowDataPacket, OkPacket, QueryError } from "mysql2"
import { getConnection } from "@/db";
import { Post, postPlaceholder } from "@/model/Models";
import { getPosts, IPost } from "@/controller/Post";
import { NextApiRequest, NextApiResponse } from "next";
export default async function handler(req: any, res: any) {
let rows:IPost[] = await getPosts();
let posts = [];
for(let row of rows){
row.post = JSON.parse(row.post).post;
console.log(row);
export default async function handler(req:NextApiRequest, res:NextApiResponse) {
switch (req.method) {
case 'GET':
let rows:IPost[] = await getPosts();
let posts = [];
for(let row of rows){
row.post = JSON.parse(row.post).post;
console.log(row);
}
res.status(200).json(rows);
break;
case 'CREATE':
break;
default:
break;
}
res.status(200).json(rows);
}