domain apis (#146)
* fix: create domain api * add domain apis * fix url --------- Co-authored-by: harshsbhat <harsh121102@gmail.com>
This commit is contained in:
45
apps/web/src/server/public-api/api/domains/create-domain.ts
Normal file
45
apps/web/src/server/public-api/api/domains/create-domain.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { createRoute, z } from "@hono/zod-openapi";
|
||||
import { DomainSchema } from "~/lib/zod/domain-schema";
|
||||
import { PublicAPIApp } from "~/server/public-api/hono";
|
||||
import { createDomain as createDomainService } from "~/server/service/domain-service";
|
||||
import { getTeamFromToken } from "~/server/public-api/auth";
|
||||
|
||||
const route = createRoute({
|
||||
method: "post",
|
||||
path: "/v1/domains",
|
||||
request: {
|
||||
body: {
|
||||
required: true,
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({
|
||||
name: z.string(),
|
||||
region: z.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
responses: {
|
||||
200: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: DomainSchema,
|
||||
},
|
||||
},
|
||||
description: "Create a new domain",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
function createDomain(app: PublicAPIApp) {
|
||||
app.openapi(route, async (c) => {
|
||||
const team = await getTeamFromToken(c);
|
||||
const body = c.req.valid("json");
|
||||
const response = await createDomainService(team.id, body.name, body.region);
|
||||
|
||||
return c.json(response);
|
||||
});
|
||||
}
|
||||
|
||||
export default createDomain;
|
49
apps/web/src/server/public-api/api/domains/verify-domain.ts
Normal file
49
apps/web/src/server/public-api/api/domains/verify-domain.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { createRoute, z } from "@hono/zod-openapi";
|
||||
import { PublicAPIApp } from "~/server/public-api/hono";
|
||||
import { getTeamFromToken } from "~/server/public-api/auth";
|
||||
import { db } from "~/server/db";
|
||||
|
||||
const route = createRoute({
|
||||
method: "put",
|
||||
path: "/v1/domains/{id}/verify",
|
||||
request: {
|
||||
params: z.object({
|
||||
id: z.coerce.number().openapi({
|
||||
param: {
|
||||
name: "id",
|
||||
in: "path",
|
||||
},
|
||||
example: 1,
|
||||
}),
|
||||
}),
|
||||
},
|
||||
responses: {
|
||||
200: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({
|
||||
message: z.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
description: "Create a new domain",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
function verifyDomain(app: PublicAPIApp) {
|
||||
app.openapi(route, async (c) => {
|
||||
const team = await getTeamFromToken(c);
|
||||
|
||||
await db.domain.update({
|
||||
where: { id: c.req.valid("param").id },
|
||||
data: { isVerifying: true },
|
||||
});
|
||||
|
||||
return c.json({
|
||||
message: "Domain verification started",
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export default verifyDomain;
|
Reference in New Issue
Block a user