Skip to content

Commit

Permalink
Merge pull request #14 from skudinva/master
Browse files Browse the repository at this point in the history
  • Loading branch information
keksobot authored Oct 22, 2024
2 parents 1e4b828 + f5417a0 commit 0b7d9f9
Show file tree
Hide file tree
Showing 57 changed files with 219 additions and 233 deletions.
2 changes: 1 addition & 1 deletion mocks/users.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { User } from '#shared/types/user.type.js';
import { User } from './../src/shared/types/user.type.js';

export const usersMock: User[] = [
{
Expand Down
10 changes: 0 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@
"api",
"node.js"
],
"imports": {
"#*": [
"./dist/src/*",
"./src/*.ts",
"./src/*.js"
],
"#mock*": [
"./mocks/*"
]
},
"main": "main.js",
"scripts": {
"start": "npm run build && node ./dist/src/main.rest.js",
Expand Down
8 changes: 4 additions & 4 deletions src/cli/commands/generate-command.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getErrorMessage } from '#shared/helpers/common.js';
import { TSVFileWriter } from '#shared/libs/file-writer/tsv-file-writer.js';
import { TSVOfferGenerator } from '#shared/libs/offer-generator/tsv-offer-generator.js';
import { MockServerData } from '#shared/types/mock-server-data.type.js';
import got from 'got';
import { getErrorMessage } from '../../shared/helpers/common.js';
import { TSVFileWriter } from '../../shared/libs/file-writer/tsv-file-writer.js';
import { TSVOfferGenerator } from '../../shared/libs/offer-generator/tsv-offer-generator.js';
import { MockServerData } from '../../shared/types/mock-server-data.type.js';
import { Command } from './command.interface.js';

export class GenerateCommand implements Command {
Expand Down
30 changes: 15 additions & 15 deletions src/cli/commands/import-command.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { getErrorMessage } from '#shared/helpers/common.js';
import { getMongoURI } from '#shared/helpers/database.js';
import { DatabaseClient } from '#shared/libs/database-client/database-client.interface.js';
import { MongoDatabaseClient } from '#shared/libs/database-client/mongo-database-client.js';
import { TSVFileReader } from '#shared/libs/file-reader/tsv-file-reader.js';
import { ConsoleLogger } from '#shared/libs/logger/console-logger.js';
import { Logger } from '#shared/libs/logger/logger.interface.js';
import { DefaultOfferService } from '#shared/modules/offer/default-offer-service.js';
import { OfferModel } from '#shared/modules/offer/offer-entity.js';
import { OfferService } from '#shared/modules/offer/offer-service.interface.js';
import { ReviewModel } from '#shared/modules/review/review-entity.js';
import { DefaultUserService } from '#shared/modules/user/default-user-service.js';
import { UserModel } from '#shared/modules/user/user-entity.js';
import { UserService } from '#shared/modules/user/user-service.interface.js';
import { Offer } from '#shared/types/offer.type.js';
import { getErrorMessage } from '../../shared/helpers/common.js';
import { getMongoURI } from '../../shared/helpers/database.js';
import { DatabaseClient } from '../../shared/libs/database-client/database-client.interface.js';
import { MongoDatabaseClient } from '../../shared/libs/database-client/mongo-database-client.js';
import { TSVFileReader } from '../../shared/libs/file-reader/tsv-file-reader.js';
import { ConsoleLogger } from '../../shared/libs/logger/console-logger.js';
import { Logger } from '../../shared/libs/logger/logger.interface.js';
import { DefaultOfferService } from '../../shared/modules/offer/default-offer-service.js';
import { OfferModel } from '../../shared/modules/offer/offer-entity.js';
import { OfferService } from '../../shared/modules/offer/offer-service.interface.js';
import { ReviewModel } from '../../shared/modules/review/review-entity.js';
import { DefaultUserService } from '../../shared/modules/user/default-user-service.js';
import { UserModel } from '../../shared/modules/user/user-entity.js';
import { UserService } from '../../shared/modules/user/user-service.interface.js';
import { Offer } from '../../shared/types/offer.type.js';
import { DEFAULT_DB_PORT, DEFAULT_USER_PASSWORD } from './command.constant.js';
import { Command } from './command.interface.js';

Expand Down
20 changes: 10 additions & 10 deletions src/rest/rest-application.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { getFullServerPath } from '#shared/helpers/common.js';
import { getMongoURI } from '#shared/helpers/database.js';
import { Config } from '#shared/libs/config/config.interface.js';
import { RestSchema } from '#shared/libs/config/rest-schema.js';
import { DatabaseClient } from '#shared/libs/database-client/database-client.interface.js';
import { Logger } from '#shared/libs/logger/logger.interface.js';
import { Controller } from '#shared/libs/rest/controller/controller.interface.js';
import { ExceptionFilter } from '#shared/libs/rest/exception-filter/exception-filter.interface.js';
import { ParseTokenMiddleware } from '#shared/libs/rest/middleware/parse-token.middleware.js';
import { Component } from '#shared/types/component.enum.js';
import cors from 'cors';
import express, { Express } from 'express';
import { inject, injectable } from 'inversify';
import { getFullServerPath } from '../../src/shared/helpers/common.js';
import { getMongoURI } from '../../src/shared/helpers/database.js';
import { Config } from '../../src/shared/libs/config/config.interface.js';
import { RestSchema } from '../../src/shared/libs/config/rest-schema.js';
import { DatabaseClient } from '../../src/shared/libs/database-client/database-client.interface.js';
import { Logger } from '../../src/shared/libs/logger/logger.interface.js';
import { Controller } from '../../src/shared/libs/rest/controller/controller.interface.js';
import { ExceptionFilter } from '../../src/shared/libs/rest/exception-filter/exception-filter.interface.js';
import { ParseTokenMiddleware } from '../../src/shared/libs/rest/middleware/parse-token.middleware.js';
import { Component } from '../../src/shared/types/component.enum.js';
import { STATIC_FILES_ROUTE, STATIC_UPLOAD_ROUTE } from './rest.constant.js';

@injectable()
Expand Down
26 changes: 13 additions & 13 deletions src/rest/rest-container.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { Config } from '#shared/libs/config/config.interface.js';
import { RestConfig } from '#shared/libs/config/rest-config.js';
import { RestSchema } from '#shared/libs/config/rest-schema.js';
import { DatabaseClient } from '#shared/libs/database-client/database-client.interface.js';
import { MongoDatabaseClient } from '#shared/libs/database-client/mongo-database-client.js';
import { Logger } from '#shared/libs/logger/logger.interface.js';
import { PinoLogger } from '#shared/libs/logger/pino-logger.js';
import { AppExceptionFilter } from '#shared/libs/rest/exception-filter/app-exception-filter.js';
import { ExceptionFilter } from '#shared/libs/rest/exception-filter/exception-filter.interface.js';
import { HttpErrorExceptionFilter } from '#shared/libs/rest/exception-filter/http-error.exception-filter.js';
import { ValidationExceptionFilter } from '#shared/libs/rest/exception-filter/validation.exception-filter.js';
import { PathTransformer } from '#shared/libs/rest/transform/path-transformer.js';
import { Component } from '#shared/types/component.enum.js';
import { Container } from 'inversify';
import { Config } from '../../src/shared/libs/config/config.interface.js';
import { RestConfig } from '../../src/shared/libs/config/rest-config.js';
import { RestSchema } from '../../src/shared/libs/config/rest-schema.js';
import { DatabaseClient } from '../../src/shared/libs/database-client/database-client.interface.js';
import { MongoDatabaseClient } from '../../src/shared/libs/database-client/mongo-database-client.js';
import { Logger } from '../../src/shared/libs/logger/logger.interface.js';
import { PinoLogger } from '../../src/shared/libs/logger/pino-logger.js';
import { AppExceptionFilter } from '../../src/shared/libs/rest/exception-filter/app-exception-filter.js';
import { ExceptionFilter } from '../../src/shared/libs/rest/exception-filter/exception-filter.interface.js';
import { HttpErrorExceptionFilter } from '../../src/shared/libs/rest/exception-filter/http-error.exception-filter.js';
import { ValidationExceptionFilter } from '../../src/shared/libs/rest/exception-filter/validation.exception-filter.js';
import { PathTransformer } from '../../src/shared/libs/rest/transform/path-transformer.js';
import { Component } from '../../src/shared/types/component.enum.js';
import { RestApplication } from './rest-application.js';

export function createRestApplicationContainer() {
Expand Down
4 changes: 2 additions & 2 deletions src/shared/helpers/common.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ApplicationError } from '#shared/libs/rest/types/application-error.enum.js';
import { ValidationErrorField } from '#shared/libs/rest/types/validation-error-field.type.js';
import { ClassConstructor, plainToInstance } from 'class-transformer';
import { ValidationError } from 'class-validator';
import { ApplicationError } from '../../../src/shared/libs/rest/types/application-error.enum.js';
import { ValidationErrorField } from '../../../src/shared/libs/rest/types/validation-error-field.type.js';

export function generateRandomValue(
min: number,
Expand Down
6 changes: 3 additions & 3 deletions src/shared/libs/config/rest-config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Config } from '#shared/libs/config/config.interface.js';
import { Logger } from '#shared/libs/logger/logger.interface.js';
import { Component } from '#shared/types/component.enum.js';
import { config } from 'dotenv';
import { inject, injectable } from 'inversify';
import { Config } from '../../../../src/shared/libs/config/config.interface.js';
import { Logger } from '../../../../src/shared/libs/logger/logger.interface.js';
import { Component } from '../../../../src/shared/types/component.enum.js';
import { configRestSchema, RestSchema } from './rest-schema.js';

@injectable()
Expand Down
4 changes: 2 additions & 2 deletions src/shared/libs/database-client/mongo-database-client.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Logger } from '#shared/libs/logger/logger.interface.js';
import { Component } from '#shared/types/component.enum.js';
import { inject, injectable } from 'inversify';
import * as Mongoose from 'mongoose';
import { setTimeout } from 'node:timers/promises';
import { Logger } from '../../../../src/shared/libs/logger/logger.interface.js';
import { Component } from '../../../../src/shared/types/component.enum.js';
import { DatabaseClient } from './database-client.interface.js';

const RETRY_COUNT = 5;
Expand Down
16 changes: 8 additions & 8 deletions src/shared/libs/file-reader/tsv-file-reader.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { usersMock } from '#mock/users.js';
import { Cities } from '#shared/const.js';
import { City } from '#shared/types/city.type.js';
import { GoodType } from '#shared/types/good-type.type.js';
import { Location } from '#shared/types/location.type.js';
import { OfferType } from '#shared/types/offer-type.enum.js';
import { Offer } from '#shared/types/offer.type.js';
import { User } from '#shared/types/user.type.js';
import EventEmitter from 'node:events';
import { createReadStream } from 'node:fs';
import { usersMock } from '../../../../mocks/users.js';
import { Cities } from '../../../../src/shared/const.js';
import { City } from '../../../../src/shared/types/city.type.js';
import { GoodType } from '../../../../src/shared/types/good-type.type.js';
import { Location } from '../../../../src/shared/types/location.type.js';
import { OfferType } from '../../../../src/shared/types/offer-type.enum.js';
import { Offer } from '../../../../src/shared/types/offer.type.js';
import { User } from '../../../../src/shared/types/user.type.js';
import { FileReader } from './file-reader.interface.js';

export class TSVFileReader extends EventEmitter implements FileReader {
Expand Down
2 changes: 1 addition & 1 deletion src/shared/libs/logger/console-logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getErrorMessage } from '#shared/helpers/common.js';
import { getErrorMessage } from '../../../../src/shared/helpers/common.js';
import { Logger } from './logger.interface.js';

export class ConsoleLogger implements Logger {
Expand Down
2 changes: 1 addition & 1 deletion src/shared/libs/logger/pino-logger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getCurrentModuleDirectoryPath } from '#shared/helpers/file-system.js';
import { injectable } from 'inversify';
import { resolve } from 'node:path';
import { Logger as PinoInstance, pino, transport } from 'pino';
import { getCurrentModuleDirectoryPath } from '../../../../src/shared/helpers/file-system.js';
import { Logger } from './logger.interface.js';

@injectable()
Expand Down
10 changes: 5 additions & 5 deletions src/shared/libs/offer-generator/tsv-offer-generator.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Cities } from '#shared/const.js';
import dayjs from 'dayjs';
import { Cities } from '../../../../src/shared/const.js';
import {
generateRandomValue,
getRandomItem,
getRandomItems,
getUniqueRandomItems,
} from '#shared/helpers/common.js';
import { MockServerData } from '#shared/types/mock-server-data.type.js';
import { OfferType } from '#shared/types/offer-type.enum.js';
import dayjs from 'dayjs';
} from '../../../../src/shared/helpers/common.js';
import { MockServerData } from '../../../../src/shared/types/mock-server-data.type.js';
import { OfferType } from '../../../../src/shared/types/offer-type.enum.js';
import { OfferGenerator } from './offer-generator.interface.js';

const MIN_PRICE = 100;
Expand Down
8 changes: 4 additions & 4 deletions src/shared/libs/rest/controller/base-controller.abstract.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Logger } from '#shared/libs/logger/logger.interface';
import { PathTransformer } from '#shared/libs/rest/transform/path-transformer.js';
import { Route } from '#shared/libs/rest/types/route.interface.js';
import { Component } from '#shared/types/component.enum.js';
import { Response, Router } from 'express';
import asyncHandler from 'express-async-handler';
import { StatusCodes } from 'http-status-codes';
import { inject, injectable } from 'inversify';
import { Component } from '../../../types/component.enum.js';
import { Logger } from '../../logger/logger.interface.js';
import { PathTransformer } from '../transform/path-transformer.js';
import { Route } from '../types/route.interface.js';
import { Controller } from './controller.interface.js';
@injectable()
export abstract class BaseController implements Controller {
Expand Down
2 changes: 1 addition & 1 deletion src/shared/libs/rest/controller/controller.interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Route } from '#shared/libs/rest/types/route.interface.js';
import { Response, Router } from 'express';
import { Route } from '../../../../../src/shared/libs/rest/types/route.interface.js';

export interface Controller {
readonly router: Router;
Expand Down
2 changes: 1 addition & 1 deletion src/shared/libs/rest/errors/validation.error.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ValidationErrorField } from '#shared/libs/rest/types/validation-error-field.type.js';
import { StatusCodes } from 'http-status-codes';
import { ValidationErrorField } from '../../../../../src/shared/libs/rest/types/validation-error-field.type.js';
import { HttpError } from './http-error.js';

export class ValidationError extends HttpError {
Expand Down
8 changes: 4 additions & 4 deletions src/shared/libs/rest/exception-filter/app-exception-filter.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { createErrorObject } from '#shared/helpers/common.js';
import { Logger } from '#shared/libs/logger/logger.interface.js';
import { ApplicationError } from '#shared/libs/rest/types/application-error.enum.js';
import { Component } from '#shared/types/component.enum.js';
import { NextFunction, Request, Response } from 'express';
import { StatusCodes } from 'http-status-codes';
import { inject, injectable } from 'inversify';
import { createErrorObject } from '../../../../../src/shared/helpers/common.js';
import { Logger } from '../../../../../src/shared/libs/logger/logger.interface.js';
import { ApplicationError } from '../../../../../src/shared/libs/rest/types/application-error.enum.js';
import { Component } from '../../../../../src/shared/types/component.enum.js';
import { ExceptionFilter } from './exception-filter.interface.js';

@injectable()
Expand Down
8 changes: 4 additions & 4 deletions src/shared/libs/rest/exception-filter/app.exception-filter.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { createErrorObject } from '#shared/helpers/common.js';
import { Logger } from '#shared/libs/logger/logger.interface.js';
import { ApplicationError } from '#shared/libs/rest/types/application-error.enum.js';
import { Component } from '#shared/types/component.enum.js';
import { NextFunction, Request, Response } from 'express';
import { StatusCodes } from 'http-status-codes';
import { inject, injectable } from 'inversify';
import { createErrorObject } from '../../../../../src/shared/helpers/common.js';
import { Logger } from '../../../../../src/shared/libs/logger/logger.interface.js';
import { ApplicationError } from '../../../../../src/shared/libs/rest/types/application-error.enum.js';
import { Component } from '../../../../../src/shared/types/component.enum.js';
import { ExceptionFilter } from './exception-filter.interface.js';

@injectable()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { createErrorObject } from '#shared/helpers/common.js';
import { Logger } from '#shared/libs/logger/logger.interface.js';
import { HttpError } from '#shared/libs/rest/errors/http-error.js';
import { ApplicationError } from '#shared/libs/rest/types/application-error.enum.js';
import { Component } from '#shared/types/component.enum.js';
import { NextFunction, Request, Response } from 'express';
import { StatusCodes } from 'http-status-codes';
import { inject, injectable } from 'inversify';
import { createErrorObject } from '../../../../../src/shared/helpers/common.js';
import { Logger } from '../../../../../src/shared/libs/logger/logger.interface.js';
import { HttpError } from '../../../../../src/shared/libs/rest/errors/http-error.js';
import { ApplicationError } from '../../../../../src/shared/libs/rest/types/application-error.enum.js';
import { Component } from '../../../../../src/shared/types/component.enum.js';
import { ExceptionFilter } from './exception-filter.interface.js';

@injectable()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { createErrorObject } from '#shared/helpers/common.js';
import { Logger } from '#shared/libs/logger/logger.interface.js';
import { ValidationError } from '#shared/libs/rest/errors/validation.error.js';
import { ApplicationError } from '#shared/libs/rest/types/application-error.enum.js';
import { Component } from '#shared/types/component.enum.js';
import { NextFunction, Request, Response } from 'express';
import { StatusCodes } from 'http-status-codes';
import { inject, injectable } from 'inversify';
import { createErrorObject } from '../../../../../src/shared/helpers/common.js';
import { Logger } from '../../../../../src/shared/libs/logger/logger.interface.js';
import { ValidationError } from '../../../../../src/shared/libs/rest/errors/validation.error.js';
import { ApplicationError } from '../../../../../src/shared/libs/rest/types/application-error.enum.js';
import { Component } from '../../../../../src/shared/types/component.enum.js';
import { ExceptionFilter } from './exception-filter.interface.js';

@injectable()
Expand Down
4 changes: 2 additions & 2 deletions src/shared/libs/rest/middleware/document-exists.middleware.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HttpError } from '#shared/libs/rest/errors/http-error.js';
import { DocumentExists } from '#shared/types/document-exists.interface.js';
import { NextFunction, Request, Response } from 'express';
import { StatusCodes } from 'http-status-codes';
import { HttpError } from '../../../../../src/shared/libs/rest/errors/http-error.js';
import { DocumentExists } from '../../../../../src/shared/types/document-exists.interface.js';
import { Middleware } from './middleware.interface.js';

export class DocumentExistsMiddleware implements Middleware {
Expand Down
4 changes: 2 additions & 2 deletions src/shared/libs/rest/middleware/parse-token.middleware.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { HttpError } from '#shared/libs/rest/errors/http-error.js';
import { TokenPayload } from '#shared/modules/auth/types/token-payload.js';
import { NextFunction, Request, Response } from 'express';
import { StatusCodes } from 'http-status-codes';
import { jwtVerify } from 'jose';
import { createSecretKey } from 'node:crypto';
import { HttpError } from '../../../../../src/shared/libs/rest/errors/http-error.js';
import { TokenPayload } from '../../../../../src/shared/modules/auth/types/token-payload.js';
import { Middleware } from './middleware.interface.js';

function isTokenPayload(payload: unknown): payload is TokenPayload {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HttpError } from '#shared/libs/rest/errors/http-error.js';
import { NextFunction, Request, Response } from 'express';
import { StatusCodes } from 'http-status-codes';
import { HttpError } from '../../../../../src/shared/libs/rest/errors/http-error.js';
import { Middleware } from './middleware.interface.js';

export class PrivateRouteMiddleware implements Middleware {
Expand Down
4 changes: 2 additions & 2 deletions src/shared/libs/rest/middleware/validate-dto.middleware.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { reduceValidationErrors } from '#shared/helpers/common.js';
import { ValidationError } from '#shared/libs/rest/errors/validation.error.js';
import { ClassConstructor, plainToInstance } from 'class-transformer';
import { validate } from 'class-validator';
import { NextFunction, Request, Response } from 'express';
import { reduceValidationErrors } from '../../../../../src/shared/helpers/common.js';
import { ValidationError } from '../../../../../src/shared/libs/rest/errors/validation.error.js';
import { Middleware } from './middleware.interface.js';

export class ValidateDtoMiddleware implements Middleware {
Expand Down
Loading

0 comments on commit 0b7d9f9

Please sign in to comment.