feat: tariff pagination
This commit is contained in:
parent
6150933766
commit
16e30f012f
@ -13,7 +13,7 @@ import type { Account } from "@/types/models/account.type";
|
|||||||
import type { GetAccountRequest, SetAccountRoleRequest, GetAccountsRequest, GetAccountsResponse } from "./types";
|
import type { GetAccountRequest, SetAccountRoleRequest, GetAccountsRequest, GetAccountsResponse } from "./types";
|
||||||
|
|
||||||
export const getAccounts = async (request: GetAccountsRequest): Promise<GetAccountsResponse> => {
|
export const getAccounts = async (request: GetAccountsRequest): Promise<GetAccountsResponse> => {
|
||||||
const { page, limit } = determinePaginationParameters(request?.query || {});
|
const { page, limit } = determinePaginationParameters(request?.query ?? {});
|
||||||
|
|
||||||
const accountsCount = await AccountModel.countDocuments();
|
const accountsCount = await AccountModel.countDocuments();
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ export const createAccount = async (request: FastifyRequest, reply: FastifyReply
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const getAccountByID = async (request: GetAccountRequest, reply: FastifyReply): Promise<Account> => {
|
export const getAccountByID = async (request: GetAccountRequest, reply: FastifyReply): Promise<Account> => {
|
||||||
const [getAccountRequestParams, error] = validateEmptyFields(request.params || {}, ["userId"]);
|
const [getAccountRequestParams, error] = validateEmptyFields(request.params ?? {}, ["userId"]);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
void reply.status(400);
|
void reply.status(400);
|
||||||
@ -139,7 +139,7 @@ export const removeAccount = async (request: FastifyRequest, reply: FastifyReply
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const removeAccountById = async (request: GetAccountRequest, reply: FastifyReply): Promise<Account> => {
|
export const removeAccountById = async (request: GetAccountRequest, reply: FastifyReply): Promise<Account> => {
|
||||||
const [{ userId }, error] = validateEmptyFields(request.params || {}, ["userId"]);
|
const [{ userId }, error] = validateEmptyFields(request.params ?? {}, ["userId"]);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
void reply.status(400);
|
void reply.status(400);
|
||||||
@ -186,7 +186,7 @@ export const deleteAccount = async (request: FastifyRequest, reply: FastifyReply
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const deleteAccountById = async (request: GetAccountRequest, reply: FastifyReply): Promise<Account> => {
|
export const deleteAccountById = async (request: GetAccountRequest, reply: FastifyReply): Promise<Account> => {
|
||||||
const [{ userId }, error] = validateEmptyFields(request.params || {}, ["userId"]);
|
const [{ userId }, error] = validateEmptyFields(request.params ?? {}, ["userId"]);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
void reply.status(400);
|
void reply.status(400);
|
||||||
|
@ -15,7 +15,7 @@ export const getPermissionById = async (
|
|||||||
request: GetPermissionByIdRequest,
|
request: GetPermissionByIdRequest,
|
||||||
reply: FastifyReply
|
reply: FastifyReply
|
||||||
): Promise<Permission | undefined> => {
|
): Promise<Permission | undefined> => {
|
||||||
const [{ permissionId }, validateParamsError] = validateEmptyFields(request.params || {}, ["permissionId"]);
|
const [{ permissionId }, validateParamsError] = validateEmptyFields(request.params ?? {}, ["permissionId"]);
|
||||||
|
|
||||||
if (validateParamsError) {
|
if (validateParamsError) {
|
||||||
void reply.status(400);
|
void reply.status(400);
|
||||||
@ -41,7 +41,7 @@ export const getPermissionById = async (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const createPermission = async (request: CreatePermissionRequest, reply: FastifyReply): Promise<Permission> => {
|
export const createPermission = async (request: CreatePermissionRequest, reply: FastifyReply): Promise<Permission> => {
|
||||||
const [permission, error] = validateEmptyFields(request.body || {}, ["name", "description"]);
|
const [permission, error] = validateEmptyFields(request.body ?? {}, ["name", "description"]);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
void reply.status(400);
|
void reply.status(400);
|
||||||
@ -57,8 +57,8 @@ export const updatePermission = async (
|
|||||||
request: UpdatePermissionRequest,
|
request: UpdatePermissionRequest,
|
||||||
reply: FastifyReply
|
reply: FastifyReply
|
||||||
): Promise<Permission | undefined> => {
|
): Promise<Permission | undefined> => {
|
||||||
const [permission, validateBodyError] = validateEmptyFields(request.body || {}, ["name", "description"]);
|
const [permission, validateBodyError] = validateEmptyFields(request.body ?? {}, ["name", "description"]);
|
||||||
const [{ permissionId }, validateParamsError] = validateEmptyFields(request.params || {}, ["permissionId"]);
|
const [{ permissionId }, validateParamsError] = validateEmptyFields(request.params ?? {}, ["permissionId"]);
|
||||||
|
|
||||||
if (validateBodyError) {
|
if (validateBodyError) {
|
||||||
void reply.status(400);
|
void reply.status(400);
|
||||||
@ -94,7 +94,7 @@ export const removePermission = async (
|
|||||||
request: GetPermissionByIdRequest,
|
request: GetPermissionByIdRequest,
|
||||||
reply: FastifyReply
|
reply: FastifyReply
|
||||||
): Promise<Permission | undefined> => {
|
): Promise<Permission | undefined> => {
|
||||||
const [{ permissionId }, validateParamsError] = validateEmptyFields(request.params || {}, ["permissionId"]);
|
const [{ permissionId }, validateParamsError] = validateEmptyFields(request.params ?? {}, ["permissionId"]);
|
||||||
|
|
||||||
if (validateParamsError) {
|
if (validateParamsError) {
|
||||||
void reply.status(400);
|
void reply.status(400);
|
||||||
@ -131,7 +131,7 @@ export const restorePermission = async (
|
|||||||
request: GetPermissionByIdRequest,
|
request: GetPermissionByIdRequest,
|
||||||
reply: FastifyReply
|
reply: FastifyReply
|
||||||
): Promise<Permission | undefined> => {
|
): Promise<Permission | undefined> => {
|
||||||
const [{ permissionId }, validateParamsError] = validateEmptyFields(request.params || {}, ["permissionId"]);
|
const [{ permissionId }, validateParamsError] = validateEmptyFields(request.params ?? {}, ["permissionId"]);
|
||||||
|
|
||||||
if (validateParamsError) {
|
if (validateParamsError) {
|
||||||
void reply.status(400);
|
void reply.status(400);
|
||||||
|
@ -103,7 +103,7 @@ export const getRole = async (request: GetRoleRequest, reply: FastifyReply) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const replaceRole = async (request: UpdateRoleRequest, reply: FastifyReply) => {
|
export const replaceRole = async (request: UpdateRoleRequest, reply: FastifyReply) => {
|
||||||
const [replaceRoleRequest, error] = validateEmptyFields(request.body || {}, ["name", "permissions"]);
|
const [replaceRoleRequest, error] = validateEmptyFields(request.body ?? {}, ["name", "permissions"]);
|
||||||
const { query } = request.params || {};
|
const { query } = request.params || {};
|
||||||
|
|
||||||
if (error || !replaceRoleRequest) {
|
if (error || !replaceRoleRequest) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { getTariffParams, tariffBody, replaceTariffParams } from "./inputs";
|
import { getTariffParams, tariffBody, replaceTariffParams, getTariffsQuerystring } from "./inputs";
|
||||||
import {
|
import {
|
||||||
getTariffReponse,
|
getTariffReponse,
|
||||||
getTariffsReponse,
|
getTariffsReponse,
|
||||||
@ -19,6 +19,7 @@ export const getTariffSchema: SwaggerSchema = {
|
|||||||
export const getTariffsSchema: SwaggerSchema = {
|
export const getTariffsSchema: SwaggerSchema = {
|
||||||
summary: "Получение списка тарифов",
|
summary: "Получение списка тарифов",
|
||||||
tags: ["tariff"],
|
tags: ["tariff"],
|
||||||
|
querystring: getTariffsQuerystring,
|
||||||
response: getTariffsReponse,
|
response: getTariffsReponse,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -12,6 +12,20 @@ export const getTariffParams: SwaggerMessage = {
|
|||||||
examples: [{ id: "507f1f77bcf86cd799439011" }],
|
examples: [{ id: "507f1f77bcf86cd799439011" }],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getTariffsQuerystring: SwaggerMessage = {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
page: {
|
||||||
|
type: "number",
|
||||||
|
description: "номер страницы",
|
||||||
|
},
|
||||||
|
limit: {
|
||||||
|
type: "number",
|
||||||
|
description: "Лимит количества аккаунтов (больше 100 не обрабатывается)",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
export const tariffBody: SwaggerMessage = {
|
export const tariffBody: SwaggerMessage = {
|
||||||
type: "object",
|
type: "object",
|
||||||
description: "Тариф",
|
description: "Тариф",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { swaggerError } from "@/utils/swagger-error";
|
import { swaggerError } from "@/utils/swagger-error";
|
||||||
|
|
||||||
import { tariff } from "./models";
|
import { tariff, tariffs } from "./models";
|
||||||
|
|
||||||
import type { SwaggerMessage } from "@/types/swagger.type";
|
import type { SwaggerMessage } from "@/types/swagger.type";
|
||||||
|
|
||||||
@ -11,11 +11,7 @@ export const getTariffReponse: Record<string, SwaggerMessage> = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const getTariffsReponse: Record<string, SwaggerMessage> = {
|
export const getTariffsReponse: Record<string, SwaggerMessage> = {
|
||||||
200: {
|
200: tariffs,
|
||||||
type: "array",
|
|
||||||
description: "Массив тарифов",
|
|
||||||
items: tariff,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createTariffReponse: Record<string, SwaggerMessage> = {
|
export const createTariffReponse: Record<string, SwaggerMessage> = {
|
||||||
|
Loading…
Reference in New Issue
Block a user