style: linting and formatting
This commit is contained in:
@@ -14,22 +14,22 @@ export async function GET(request: Request) {
|
||||
const response = await hackernewsApi();
|
||||
|
||||
return new NextResponse(JSON.stringify(response), {
|
||||
status: 200,
|
||||
status: 200
|
||||
});
|
||||
}
|
||||
|
||||
async function hackernewsApi() {
|
||||
const topstories: number[] = await fetch(topNews).then((res) => res.json());
|
||||
const topstories: number[] = await fetch(topNews).then(res => res.json());
|
||||
|
||||
console.log('topstories', topstories);
|
||||
|
||||
const newsPromises = topstories
|
||||
.splice(0, Number(process.env.NEWS_LIMIT))
|
||||
.map(async (id) => {
|
||||
.map(async id => {
|
||||
console.log('id', id);
|
||||
const sourceNews: z.infer<typeof NewsSchema> = await fetch(
|
||||
singleNews(id)
|
||||
).then((res) => res.json());
|
||||
).then(res => res.json());
|
||||
|
||||
console.log('sourceNews', sourceNews);
|
||||
|
||||
@@ -42,7 +42,7 @@ async function hackernewsApi() {
|
||||
by: sourceNews.by,
|
||||
time: sourceNews.time,
|
||||
url: sourceNews.url,
|
||||
score: sourceNews.score,
|
||||
score: sourceNews.score
|
||||
},
|
||||
update: {
|
||||
title: sourceNews.title,
|
||||
@@ -51,18 +51,18 @@ async function hackernewsApi() {
|
||||
by: sourceNews.by,
|
||||
time: sourceNews.time,
|
||||
url: sourceNews.url,
|
||||
score: sourceNews.score,
|
||||
score: sourceNews.score
|
||||
},
|
||||
where: {
|
||||
id,
|
||||
id
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
id: true
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const newsIds = await Promise.all(newsPromises);
|
||||
|
||||
return newsIds.map((news) => news.id);
|
||||
return newsIds.map(news => news.id);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { z } from 'zod';
|
||||
import { fromZodError } from 'zod-validation-error';
|
||||
import prisma from '../../../prisma/prisma';
|
||||
import { ResponseSchema, SubscribeFormSchema } from '../../utils/types';
|
||||
|
||||
@@ -7,7 +8,8 @@ export async function POST(request: Request) {
|
||||
const body = await request.json();
|
||||
const validation = SubscribeFormSchema.safeParse(body);
|
||||
if (!validation.success) {
|
||||
return new Response('Bad request', { status: 400 });
|
||||
const message = fromZodError(validation.error);
|
||||
return new Response(message.message, { status: 400 });
|
||||
}
|
||||
|
||||
const { email, targetingAllowed } = validation.data;
|
||||
@@ -15,18 +17,18 @@ export async function POST(request: Request) {
|
||||
await prisma.user.upsert({
|
||||
create: {
|
||||
email,
|
||||
targetingAllowed,
|
||||
targetingAllowed
|
||||
},
|
||||
update: {
|
||||
targetingAllowed,
|
||||
targetingAllowed
|
||||
},
|
||||
where: {
|
||||
email,
|
||||
},
|
||||
email
|
||||
}
|
||||
});
|
||||
|
||||
const message: z.infer<typeof ResponseSchema> = {
|
||||
message: `${email} subscribed!`,
|
||||
message: `${email} subscribed!`
|
||||
};
|
||||
return new Response(JSON.stringify(message), { status: 200 });
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { z } from 'zod';
|
||||
import { fromZodError } from 'zod-validation-error';
|
||||
import prisma from '../../../prisma/prisma';
|
||||
import { ResponseSchema, UnsubscribeFormSchema } from '../../utils/types';
|
||||
|
||||
@@ -7,7 +8,8 @@ export async function POST(request: Request) {
|
||||
const body = await request.json();
|
||||
const validation = UnsubscribeFormSchema.safeParse(body);
|
||||
if (!validation.success) {
|
||||
return new Response('Bad request', { status: 400 });
|
||||
const message = fromZodError(validation.error);
|
||||
return new Response(message.message, { status: 400 });
|
||||
}
|
||||
|
||||
const { email } = validation.data;
|
||||
@@ -15,15 +17,15 @@ export async function POST(request: Request) {
|
||||
try {
|
||||
await prisma.user.delete({
|
||||
where: {
|
||||
email,
|
||||
},
|
||||
email
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
|
||||
const message: z.infer<typeof ResponseSchema> = {
|
||||
message: `${email} unsubscribe!`,
|
||||
message: `${email} unsubscribe!`
|
||||
};
|
||||
return new Response(JSON.stringify(message), { status: 200 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user