Skip to content

Commit

Permalink
chore: fix domain names and exports
Browse files Browse the repository at this point in the history
  • Loading branch information
brunotot committed Apr 21, 2024
1 parent 1470ea7 commit b7d5259
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 80 deletions.
88 changes: 44 additions & 44 deletions packages/backend/src/domain/ErrorLogDomain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,52 @@ import { AbstractDomain, makeDomain } from "@internal";
import mongoose from "mongoose";
import z from "zod";

export const errorLogDomain = makeDomain(
class extends AbstractDomain {
zod = z
.object({
details: z.string().min(0).openapi({
example: "Request body validation error",
}),
status: z.number().openapi({
example: 400,
}),
message: z.string().openapi({
example:
"The server cannot or will not process the request due to an apparent client error.",
}),
path: z.string().openapi({
example: "/auth/login",
}),
timestamp: z.string().openapi({
example: "2024-01-01T00:00:00.000Z",
export class ErrorLogDomain extends AbstractDomain {
zod = z
.object({
details: z.string().min(0).openapi({
example: "Request body validation error",
}),
status: z.number().openapi({
example: 400,
}),
message: z.string().openapi({
example:
"The server cannot or will not process the request due to an apparent client error.",
}),
path: z.string().openapi({
example: "/auth/login",
}),
timestamp: z.string().openapi({
example: "2024-01-01T00:00:00.000Z",
}),
metadata: z
.record(z.string(), z.any())

.openapi({
example: {
errors: [
"[password] String must contain at least 1 character(s)",
"[username] String must contain at least 1 character(s)",
],
},
}),
metadata: z
.record(z.string(), z.any())
})
.describe("ErrorLog");

.openapi({
example: {
errors: [
"[password] String must contain at least 1 character(s)",
"[username] String must contain at least 1 character(s)",
],
},
}),
})
.describe("ErrorLog");
schema = new mongoose.Schema<z.infer<typeof this.zod>>(
{
details: { type: String, required: true },
status: { type: Number, required: true },
message: { type: String, required: true },
path: { type: String, required: true },
timestamp: { type: String, required: true },
metadata: { type: Object },
},
{ capped: 2048 },
);
}

schema = new mongoose.Schema<z.infer<typeof this.zod>>(
{
details: { type: String, required: true },
status: { type: Number, required: true },
message: { type: String, required: true },
path: { type: String, required: true },
timestamp: { type: String, required: true },
metadata: { type: Object },
},
{ capped: 2048 },
);
},
);
export const errorLogDomain = makeDomain(ErrorLogDomain);

export type ErrorLog = z.infer<(typeof errorLogDomain)["zod"]>;
40 changes: 20 additions & 20 deletions packages/backend/src/domain/UserDomain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ import { Role } from "@org/shared";
import mongoose from "mongoose";
import z from "zod";

export const userDomain = makeDomain(
class extends AbstractDomain {
zod = z
.object({
username: z.string().openapi({ example: "john_doe" }),
password: z.string().openapi({ example: "password" }),
email: z.string().email().openapi({ example: "john.doe@mail.com" }),
roles: z.array(Role).openapi({ example: [Role.enum.USER, Role.enum.ADMIN] }),
refreshToken: z.array(z.string()),
})
.describe("User");
export class UserDomain extends AbstractDomain {
zod = z
.object({
username: z.string().openapi({ example: "john_doe" }),
password: z.string().openapi({ example: "password" }),
email: z.string().email().openapi({ example: "john.doe@mail.com" }),
roles: z.array(Role).openapi({ example: [Role.enum.USER, Role.enum.ADMIN] }),
refreshToken: z.array(z.string()),
})
.describe("User");

schema = new mongoose.Schema<z.infer<typeof this.zod>>({
username: { type: String, required: true },
password: { type: String, required: true },
email: { type: String, required: true },
roles: { type: [String], required: true },
refreshToken: { type: [String] },
});
},
);
schema = new mongoose.Schema<z.infer<typeof this.zod>>({
username: { type: String, required: true },
password: { type: String, required: true },
email: { type: String, required: true },
roles: { type: [String], required: true },
refreshToken: { type: [String] },
});
}

export const userDomain = makeDomain(UserDomain);

export type User = z.infer<(typeof userDomain)["zod"]>;
16 changes: 0 additions & 16 deletions packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,4 @@

import "@types";

import "./config/zod/environment";

import "./decorators/config/bottlejs";

import "./config/logger";

import "./infrastructure/middleware/globals/index";

import "./infrastructure/repository/impl/UserRepositoryImpl";

import "./infrastructure/service/impl/UserServiceImpl";

import "./web/controllers/AuthController";

import "./web/controllers/UserController";

export * from "./internal";

0 comments on commit b7d5259

Please sign in to comment.