Files
stats/apps/web/src/pages/api/sdk/profiles/[profileId]/increment.ts
2023-10-12 23:19:02 +02:00

34 lines
933 B
TypeScript

import { validateSdkRequest } from "@/server/auth";
import { db } from "@/server/db";
import { createError, handleError } from "@/server/exceptions";
import { tickProfileProperty } from "@/services/profile.service";
import { ProfileIncrementPayload, ProfilePayload } from "@mixan/types";
import type { NextApiRequest, NextApiResponse } from "next";
interface Request extends NextApiRequest {
body: ProfileIncrementPayload;
}
export default async function handler(req: Request, res: NextApiResponse) {
if (req.method !== "PUT") {
return handleError(res, createError(405, "Method not allowed"));
}
try {
// Check client id & secret
await validateSdkRequest(req)
const profileId = req.query.profileId as string;
await tickProfileProperty({
name: req.body.name,
tick: req.body.value,
profileId,
});
res.status(200).end();
} catch (error) {
handleError(res, error);
}
}