Compare commits

..

No commits in common. '088acc515d729f4ec994b331a96e77a10a3fe69f' and '4ee47eba4bc103ad8659b6b861c1d660da9e713e' have entirely different histories.

  1. 201
      package-lock.json
  2. 4
      package.json
  3. 7
      src/app.module.ts
  4. 3
      src/core/constants/index.ts
  5. 16
      src/core/database/database.providers.ts
  6. 5
      src/modules/orders/dto/create-order.dto.ts
  7. 9
      src/modules/orders/entities/order.entity.ts
  8. 6
      src/modules/products/products.controller.ts
  9. 17
      src/modules/products/products.module.ts
  10. 8
      src/modules/products/products.service.ts
  11. 5
      src/modules/receipts/dto/create-receipt.dto.ts
  12. 2
      src/modules/receipts/dto/index.ts
  13. 4
      src/modules/receipts/dto/update-receipt.dto.ts
  14. 32
      src/modules/receipts/entities/receipt.entity.ts
  15. 37
      src/modules/receipts/receipts.controller.ts
  16. 11
      src/modules/receipts/receipts.module.ts
  17. 9
      src/modules/receipts/receipts.providers.ts
  18. 34
      src/modules/receipts/receipts.service.ts
  19. 7
      src/modules/shopping-cards/dto/create-shopping-card.dto.ts
  20. 2
      src/modules/shopping-cards/dto/index.ts
  21. 4
      src/modules/shopping-cards/dto/update-shopping-card.dto.ts
  22. 32
      src/modules/shopping-cards/entities/shopping-card.entity.ts
  23. 51
      src/modules/shopping-cards/shopping-cards.controller.ts
  24. 26
      src/modules/shopping-cards/shopping-cards.module.ts
  25. 9
      src/modules/shopping-cards/shopping-cards.providers.ts
  26. 91
      src/modules/shopping-cards/shopping-cards.service.ts
  27. 27
      src/modules/users/dto/create-user.dto.ts
  28. 8
      src/modules/users/entities/user.entity.ts
  29. 5
      src/modules/wallets-transactions/dto/create-wallets-transaction.dto.ts
  30. 14
      src/modules/wallets-transactions/entities/transaction-operation.entity.ts
  31. 34
      src/modules/wallets-transactions/entities/wallets-transaction.entity.ts
  32. 33
      src/modules/wallets-transactions/wallets-transactions.controller.ts
  33. 11
      src/modules/wallets-transactions/wallets-transactions.module.ts
  34. 9
      src/modules/wallets-transactions/wallets-transactions.providers.ts
  35. 31
      src/modules/wallets-transactions/wallets-transactions.service.ts
  36. 12
      src/modules/wallets/wallets.module.ts
  37. 27
      src/modules/wallets/wallets.service.ts

201
package-lock.json generated

@ -9,7 +9,6 @@
"version": "0.0.1",
"license": "UNLICENSED",
"dependencies": {
"@nestjs/cache-manager": "^2.3.0",
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.3.0",
"@nestjs/core": "^10.0.0",
@ -18,9 +17,6 @@
"@nestjs/passport": "^10.0.3",
"@nestjs/platform-express": "^10.0.0",
"argon2": "^0.41.1",
"cache-manager-redis-yet": "^5.1.5",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"dotenv": "^16.4.7",
"lodash": "^4.17.21",
"passport": "^0.7.0",
@ -1582,18 +1578,6 @@
"node": ">=8"
}
},
"node_modules/@nestjs/cache-manager": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/@nestjs/cache-manager/-/cache-manager-2.3.0.tgz",
"integrity": "sha512-pxeBp9w/s99HaW2+pezM1P3fLiWmUEnTUoUMLa9UYViCtjj0E0A19W/vaT5JFACCzFIeNrwH4/16jkpAhQ25Vw==",
"license": "MIT",
"peerDependencies": {
"@nestjs/common": "^9.0.0 || ^10.0.0",
"@nestjs/core": "^9.0.0 || ^10.0.0",
"cache-manager": "<=5",
"rxjs": "^7.0.0"
}
},
"node_modules/@nestjs/cli": {
"version": "10.4.9",
"resolved": "https://registry.npmjs.org/@nestjs/cli/-/cli-10.4.9.tgz",
@ -1939,71 +1923,6 @@
"url": "https://opencollective.com/unts"
}
},
"node_modules/@redis/bloom": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/@redis/bloom/-/bloom-1.2.0.tgz",
"integrity": "sha512-HG2DFjYKbpNmVXsa0keLHp/3leGJz1mjh09f2RLGGLQZzSHpkmZWuwJbAvo3QcRY8p80m5+ZdXZdYOSBLlp7Cg==",
"license": "MIT",
"peerDependencies": {
"@redis/client": "^1.0.0"
}
},
"node_modules/@redis/client": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/@redis/client/-/client-1.6.0.tgz",
"integrity": "sha512-aR0uffYI700OEEH4gYnitAnv3vzVGXCFvYfdpu/CJKvk4pHfLPEy/JSZyrpQ+15WhXe1yJRXLtfQ84s4mEXnPg==",
"license": "MIT",
"dependencies": {
"cluster-key-slot": "1.1.2",
"generic-pool": "3.9.0",
"yallist": "4.0.0"
},
"engines": {
"node": ">=14"
}
},
"node_modules/@redis/client/node_modules/yallist": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==",
"license": "ISC"
},
"node_modules/@redis/graph": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@redis/graph/-/graph-1.1.1.tgz",
"integrity": "sha512-FEMTcTHZozZciLRl6GiiIB4zGm5z5F3F6a6FZCyrfxdKOhFlGkiAqlexWMBzCi4DcRoyiOsuLfW+cjlGWyExOw==",
"license": "MIT",
"peerDependencies": {
"@redis/client": "^1.0.0"
}
},
"node_modules/@redis/json": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/@redis/json/-/json-1.0.7.tgz",
"integrity": "sha512-6UyXfjVaTBTJtKNG4/9Z8PSpKE6XgSyEb8iwaqDcy+uKrd/DGYHTWkUdnQDyzm727V7p21WUMhsqz5oy65kPcQ==",
"license": "MIT",
"peerDependencies": {
"@redis/client": "^1.0.0"
}
},
"node_modules/@redis/search": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/@redis/search/-/search-1.2.0.tgz",
"integrity": "sha512-tYoDBbtqOVigEDMAcTGsRlMycIIjwMCgD8eR2t0NANeQmgK/lvxNAvYyb6bZDD4frHRhIHkJu2TBRvB0ERkOmw==",
"license": "MIT",
"peerDependencies": {
"@redis/client": "^1.0.0"
}
},
"node_modules/@redis/time-series": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@redis/time-series/-/time-series-1.1.0.tgz",
"integrity": "sha512-c1Q99M5ljsIuc4YdaCwfUEXsofakb9c8+Zse2qxTadu8TalLXuAESzLvFAvNVbkmSlvlzIQOLpBCmWI9wTOt+g==",
"license": "MIT",
"peerDependencies": {
"@redis/client": "^1.0.0"
}
},
"node_modules/@sinclair/typebox": {
"version": "0.27.8",
"resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.8.tgz",
@ -3468,47 +3387,6 @@
"node": ">= 0.8"
}
},
"node_modules/cache-manager": {
"version": "5.7.6",
"resolved": "https://registry.npmjs.org/cache-manager/-/cache-manager-5.7.6.tgz",
"integrity": "sha512-wBxnBHjDxF1RXpHCBD6HGvKER003Ts7IIm0CHpggliHzN1RZditb7rXoduE1rplc2DEFYKxhLKgFuchXMJje9w==",
"license": "MIT",
"dependencies": {
"eventemitter3": "^5.0.1",
"lodash.clonedeep": "^4.5.0",
"lru-cache": "^10.2.2",
"promise-coalesce": "^1.1.2"
},
"engines": {
"node": ">= 18"
}
},
"node_modules/cache-manager-redis-yet": {
"version": "5.1.5",
"resolved": "https://registry.npmjs.org/cache-manager-redis-yet/-/cache-manager-redis-yet-5.1.5.tgz",
"integrity": "sha512-NYDxrWBoLXxxVPw4JuBriJW0f45+BVOAsgLiozRo4GoJQyoKPbueQWYStWqmO73/AeHJeWrV7Hzvk6vhCGHlqA==",
"deprecated": "With cache-manager v6 we now are using Keyv",
"license": "MIT",
"dependencies": {
"@redis/bloom": "^1.2.0",
"@redis/client": "^1.6.0",
"@redis/graph": "^1.1.1",
"@redis/json": "^1.0.7",
"@redis/search": "^1.2.0",
"@redis/time-series": "^1.1.0",
"cache-manager": "^5.7.6",
"redis": "^4.7.0"
},
"engines": {
"node": ">= 18"
}
},
"node_modules/cache-manager/node_modules/lru-cache": {
"version": "10.4.3",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.3.tgz",
"integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==",
"license": "ISC"
},
"node_modules/call-bind": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.8.tgz",
@ -3689,23 +3567,6 @@
"dev": true,
"license": "MIT"
},
"node_modules/class-transformer": {
"version": "0.5.1",
"resolved": "https://registry.npmjs.org/class-transformer/-/class-transformer-0.5.1.tgz",
"integrity": "sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw==",
"license": "MIT"
},
"node_modules/class-validator": {
"version": "0.14.1",
"resolved": "https://registry.npmjs.org/class-validator/-/class-validator-0.14.1.tgz",
"integrity": "sha512-2VEG9JICxIqTpoK1eMzZqaV+u/EiwEJkMGzTrZf6sU/fwsnOITVgYJ8yojSy6CaXtO9V0Cc6ZQZ8h8m4UBuLwQ==",
"license": "MIT",
"dependencies": {
"@types/validator": "^13.11.8",
"libphonenumber-js": "^1.10.53",
"validator": "^13.9.0"
}
},
"node_modules/cli-cursor": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz",
@ -3801,15 +3662,6 @@
"node": ">=0.8"
}
},
"node_modules/cluster-key-slot": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/cluster-key-slot/-/cluster-key-slot-1.1.2.tgz",
"integrity": "sha512-RMr0FhtfXemyinomL4hrWcYJxmX6deFdCxpJzhDttxgO1+bcCnkk+9drydLVDmAMG7NE6aN/fl4F7ucU/90gAA==",
"license": "Apache-2.0",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/co": {
"version": "4.6.0",
"resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz",
@ -4710,12 +4562,6 @@
"node": ">= 0.6"
}
},
"node_modules/eventemitter3": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.1.tgz",
"integrity": "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==",
"license": "MIT"
},
"node_modules/events": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz",
@ -5253,15 +5099,6 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/generic-pool": {
"version": "3.9.0",
"resolved": "https://registry.npmjs.org/generic-pool/-/generic-pool-3.9.0.tgz",
"integrity": "sha512-hymDOu5B53XvN4QT9dBmZxPX4CWhBPPLguTZ9MMFeFa/Kg0xWVfylOVNlJji/E7yTZWFd/q9GO5TxDLq156D7g==",
"license": "MIT",
"engines": {
"node": ">= 4"
}
},
"node_modules/gensync": {
"version": "1.0.0-beta.2",
"resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz",
@ -6863,12 +6700,6 @@
"node": ">= 0.8.0"
}
},
"node_modules/libphonenumber-js": {
"version": "1.11.17",
"resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.11.17.tgz",
"integrity": "sha512-Jr6v8thd5qRlOlc6CslSTzGzzQW03uiscab7KHQZX1Dfo4R6n6FDhZ0Hri6/X7edLIDv9gl4VMZXhxTjLnl0VQ==",
"license": "MIT"
},
"node_modules/lines-and-columns": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz",
@ -6908,12 +6739,6 @@
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
"license": "MIT"
},
"node_modules/lodash.clonedeep": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz",
"integrity": "sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ==",
"license": "MIT"
},
"node_modules/lodash.includes": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz",
@ -8045,15 +7870,6 @@
"integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==",
"license": "MIT"
},
"node_modules/promise-coalesce": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/promise-coalesce/-/promise-coalesce-1.1.2.tgz",
"integrity": "sha512-zLaJ9b8hnC564fnJH6NFSOGZYYdzrAJn2JUUIwzoQb32fG2QAakpDNM+CZo1km6keXkRXRM+hml1BFAPVnPkxg==",
"license": "BSD-3-Clause",
"engines": {
"node": ">=16"
}
},
"node_modules/prompts": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.2.tgz",
@ -8232,23 +8048,6 @@
"url": "https://github.com/sponsors/jonschlinkert"
}
},
"node_modules/redis": {
"version": "4.7.0",
"resolved": "https://registry.npmjs.org/redis/-/redis-4.7.0.tgz",
"integrity": "sha512-zvmkHEAdGMn+hMRXuMBtu4Vo5P6rHQjLoHftu+lBqq8ZTA3RCVC/WzD790bkKKiNFp7d5/9PcSD19fJyyRvOdQ==",
"license": "MIT",
"workspaces": [
"./packages/*"
],
"dependencies": {
"@redis/bloom": "1.2.0",
"@redis/client": "1.6.0",
"@redis/graph": "1.1.1",
"@redis/json": "1.0.7",
"@redis/search": "1.2.0",
"@redis/time-series": "1.1.0"
}
},
"node_modules/reflect-metadata": {
"version": "0.2.2",
"resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.2.2.tgz",

@ -20,7 +20,6 @@
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@nestjs/cache-manager": "^2.3.0",
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.3.0",
"@nestjs/core": "^10.0.0",
@ -29,9 +28,6 @@
"@nestjs/passport": "^10.0.3",
"@nestjs/platform-express": "^10.0.0",
"argon2": "^0.41.1",
"cache-manager-redis-yet": "^5.1.5",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"dotenv": "^16.4.7",
"lodash": "^4.17.21",
"passport": "^0.7.0",

@ -9,10 +9,6 @@ import { ProductsModule } from './modules/products/products.module';
import { AuthModule } from './modules/auth/auth.module';
import { OrdersModule } from './modules/orders/orders.module';
import { WalletsModule } from './modules/wallets/wallets.module';
import { WalletsTransactionsModule } from './modules/wallets-transactions/wallets-transactions.module';
import { ReceiptsModule } from './modules/receipts/receipts.module';
import { ShoppingCardsModule } from './modules/shopping-cards/shopping-cards.module';
import { CacheModule } from '@nestjs/cache-manager';
@Module({
imports: [
@ -23,9 +19,6 @@ import { CacheModule } from '@nestjs/cache-manager';
AuthModule,
OrdersModule,
WalletsModule,
WalletsTransactionsModule,
ReceiptsModule,
ShoppingCardsModule,
],
controllers: [AppController, UsersController],
providers: [AppService],

@ -7,6 +7,3 @@ export const PRODUCT_REPOSITORY = 'PRODUCT_REPOSITORY';
export const ORDER_REPOSITORY = 'ORDER_REPOSITORY';
export const ORDER_STATUSES_REPOSITORY = 'ORDER_STATUSES_REPOSITORY';
export const WALLET_REPOSITORY = 'WALLET_REPOSITORY';
export const WALLET_TRANSACTIONS_REPOSITORY = 'WALLET_TRANSACTIONS_REPOSITORY';
export const RECEIPT_REPOSITORY = 'RECEIPT_REPOSITORY';
export const SHOPPING_CARD_REPOSITORY = 'SHOPPING_CARD_REPOSITORY';

@ -6,10 +6,6 @@ import { Product } from 'src/modules/products/entities/product.entity';
import { OrderStatuses } from 'src/modules/orders/entities/order-status.entity';
import { Order } from 'src/modules/orders/entities/order.entity';
import { Wallet } from 'src/modules/wallets/entities/wallet.entity';
import { TransactionOperations } from 'src/modules/wallets-transactions/entities/transaction-operation.entity';
import { WalletsTransactions } from 'src/modules/wallets-transactions/entities/wallets-transaction.entity';
import { Receipt } from 'src/modules/receipts/entities/receipt.entity';
import { ShoppingCard } from 'src/modules/shopping-cards/entities/shopping-card.entity';
export const databaseProviders = [
{
@ -30,17 +26,7 @@ export const databaseProviders = [
config = databaseConfig.development;
}
const sequelize = new Sequelize(config);
sequelize.addModels([
User,
Product,
Order,
OrderStatuses,
Wallet,
TransactionOperations,
WalletsTransactions,
Receipt,
ShoppingCard,
]);
sequelize.addModels([User, Product, Order, OrderStatuses, Wallet]);
await sequelize.sync();
return sequelize;
},

@ -1,9 +1,8 @@
export class CreateOrderDto {
userId: number;
orderDate?: Date;
orderDate: Date;
status: number;
comments: string;
shippedDate?: Date;
shippedDate: Date;
shipperName: string;
products: number[];
}

@ -8,23 +8,16 @@ import {
} from 'sequelize-typescript';
import { User } from 'src/modules/users/entities/user.entity';
import { OrderStatuses } from 'src/modules/orders/entities/order-status.entity';
import { Product } from 'src/modules/products/entities/product.entity';
@Table({ tableName: 'orders' })
export class Order extends Model<Order> {
@Column({
type: DataType.DATE,
allowNull: true,
allowNull: false,
defaultValue: new Date(),
})
orderDate: Date;
@Column({
type: DataType.ARRAY(DataType.INTEGER),
allowNull: false,
})
products: number[];
@ForeignKey(() => OrderStatuses)
@Column
status: number;

@ -10,6 +10,7 @@ import {
} from '@nestjs/common';
import { ProductsService } from './products.service';
import { CreateProductDto, UpdateProductDto } from './dto';
import { UUID } from 'crypto';
import { AuthGuard } from '@nestjs/passport';
@Controller('products')
@ -22,11 +23,6 @@ export class ProductsController {
return this.productsService.create(createProductDto);
}
@Post('add/:id/:user')
addProduct(@Param('id') id: number, @Param('user') userId: number) {
return this.productsService.addProduct(id, userId);
}
@Get()
findAll() {
return this.productsService.findAll();

@ -2,25 +2,10 @@ import { Module } from '@nestjs/common';
import { ProductsService } from './products.service';
import { ProductsController } from './products.controller';
import { productsProviders } from './products.providers';
import { ShoppingCardsService } from '../shopping-cards/shopping-cards.service';
import { ReceiptsService } from '../receipts/receipts.service';
import { shoppingCardsProviders } from '../shopping-cards/shopping-cards.providers';
import { receiptsProviders } from '../receipts/receipts.providers';
import { OrdersService } from '../orders/orders.service';
import { ordersProviders } from '../orders/orders.providers';
@Module({
controllers: [ProductsController],
exports: [ProductsService],
providers: [
ProductsService,
...productsProviders,
ShoppingCardsService,
ReceiptsService,
...shoppingCardsProviders,
...receiptsProviders,
OrdersService,
...ordersProviders,
],
providers: [ProductsService, ...productsProviders],
})
export class ProductsModule {}

@ -2,14 +2,12 @@ import { Inject, Injectable } from '@nestjs/common';
import { CreateProductDto, UpdateProductDto } from './dto';
import { PRODUCT_REPOSITORY } from 'src/core/constants';
import { Product } from './entities/product.entity';
import { ShoppingCardsService } from '../shopping-cards/shopping-cards.service';
@Injectable()
export class ProductsService {
constructor(
@Inject(PRODUCT_REPOSITORY)
private readonly productRepository: typeof Product,
// private readonly shoppingCardsService: ShoppingCardsService,
) {}
async create(createProductDto: CreateProductDto) {
@ -40,10 +38,4 @@ export class ProductsService {
return deletedProduct;
}
async addProduct(id: number, userId: number) {
// const [card] = await this.shoppingCardsService.findbyUser(userId);
// card.products.push(id);
// return await card.save();
}
}

@ -1,5 +0,0 @@
export class CreateReceiptDto {
userId: number;
totalPrice: number;
products: number[];
}

@ -1,2 +0,0 @@
export * from './create-receipt.dto';
export * from './update-receipt.dto';

@ -1,4 +0,0 @@
import { PartialType } from '@nestjs/mapped-types';
import { CreateReceiptDto } from './create-receipt.dto';
export class UpdateReceiptDto extends PartialType(CreateReceiptDto) {}

@ -1,32 +0,0 @@
import {
Table,
Column,
Model,
DataType,
ForeignKey,
BelongsTo,
} from 'sequelize-typescript';
import { Product } from 'src/modules/products/entities/product.entity';
import { User } from 'src/modules/users/entities/user.entity';
@Table({ tableName: 'receipts', updatedAt: false })
export class Receipt extends Model<Receipt> {
@Column({
type: DataType.FLOAT,
allowNull: false,
})
totalPrice: number;
@Column({
type: DataType.ARRAY(DataType.INTEGER),
allowNull: false,
})
products: number[];
@ForeignKey(() => User)
@Column
userId: number;
@BelongsTo(() => User)
user: User;
}

@ -1,37 +0,0 @@
import {
Controller,
Get,
Post,
Body,
Patch,
Param,
Delete,
} from '@nestjs/common';
import { ReceiptsService } from './receipts.service';
import { CreateReceiptDto } from './dto/create-receipt.dto';
import { UpdateReceiptDto } from './dto/update-receipt.dto';
@Controller('receipts')
export class ReceiptsController {
constructor(private readonly receiptsService: ReceiptsService) {}
@Post()
create(@Body() createReceiptDto: CreateReceiptDto) {
return this.receiptsService.create(createReceiptDto);
}
@Get()
findAll() {
return this.receiptsService.findAll();
}
@Get('users/:id')
findByUser(@Param('id') id: string) {
return this.receiptsService.findByUser(+id);
}
@Delete(':id')
remove(@Param('id') id: string) {
return this.receiptsService.remove(+id);
}
}

@ -1,11 +0,0 @@
import { Module } from '@nestjs/common';
import { ReceiptsService } from './receipts.service';
import { ReceiptsController } from './receipts.controller';
import { receiptsProviders } from './receipts.providers';
@Module({
controllers: [ReceiptsController],
providers: [ReceiptsService, ...receiptsProviders],
exports: [ReceiptsService],
})
export class ReceiptsModule {}

@ -1,9 +0,0 @@
import { Receipt } from './entities/receipt.entity';
import { RECEIPT_REPOSITORY } from '../../core/constants';
export const receiptsProviders = [
{
provide: RECEIPT_REPOSITORY,
useValue: Receipt,
},
];

@ -1,34 +0,0 @@
import { Inject, Injectable } from '@nestjs/common';
import { CreateReceiptDto, UpdateReceiptDto } from './dto';
import { RECEIPT_REPOSITORY } from 'src/core/constants';
import { Receipt } from './entities/receipt.entity';
@Injectable()
export class ReceiptsService {
constructor(
@Inject(RECEIPT_REPOSITORY)
private readonly receiptRepository: typeof Receipt,
) {}
async create(createReceiptDto: CreateReceiptDto) {
return await this.receiptRepository.create(createReceiptDto);
}
async findAll() {
return await this.receiptRepository.findAll();
}
async findByUser(id: number) {
return await this.receiptRepository.findAll({ where: { userId: id } });
}
async remove(id: number) {
const deletedReceipt = await this.receiptRepository.findAll({
where: { id },
});
await this.receiptRepository.destroy({ where: { id } });
return deletedReceipt;
}
}

@ -1,7 +0,0 @@
import { Product } from 'src/modules/products/entities/product.entity';
export class CreateShoppingCardDto {
userId: number;
products: number[];
totalPrice: number;
}

@ -1,2 +0,0 @@
export * from './create-shopping-card.dto';
export * from './update-shopping-card.dto';

@ -1,4 +0,0 @@
import { PartialType } from '@nestjs/mapped-types';
import { CreateShoppingCardDto } from './create-shopping-card.dto';
export class UpdateShoppingCardDto extends PartialType(CreateShoppingCardDto) {}

@ -1,32 +0,0 @@
import {
Table,
Column,
Model,
DataType,
ForeignKey,
BelongsTo,
} from 'sequelize-typescript';
import { User } from 'src/modules/users/entities/user.entity';
@Table({ tableName: 'shopping_cards' })
export class ShoppingCard extends Model<ShoppingCard> {
@Column({
type: DataType.FLOAT,
allowNull: false,
defaultValue: 0,
})
totalPrice: number;
@Column({
type: DataType.ARRAY(DataType.INTEGER),
allowNull: false,
})
products: number[];
@ForeignKey(() => User)
@Column
userId: number;
@BelongsTo(() => User)
user: User;
}

@ -1,51 +0,0 @@
import {
Controller,
Get,
Post,
Body,
Patch,
Param,
Delete,
} from '@nestjs/common';
import { ShoppingCardsService } from './shopping-cards.service';
import { CreateShoppingCardDto, UpdateShoppingCardDto } from './dto';
import { ReceiptsService } from '../receipts/receipts.service';
import { CreateReceiptDto } from '../receipts/dto';
@Controller('shopping-cards')
export class ShoppingCardsController {
constructor(private readonly shoppingCardsService: ShoppingCardsService) {}
@Post()
create(@Body() createShoppingCardDto: CreateShoppingCardDto) {
return this.shoppingCardsService.create(createShoppingCardDto);
}
@Get()
findAll() {
return this.shoppingCardsService.findAll();
}
@Get(':id')
findbyUser(@Param('id') id: string) {
return this.shoppingCardsService.findbyUser(+id);
}
@Patch(':id')
update(
@Param('id') id: string,
@Body() updateShoppingCardDto: UpdateShoppingCardDto,
) {
return this.shoppingCardsService.update(+id, updateShoppingCardDto);
}
@Delete('/purchase/:id')
submitPurchase(@Param('id') id: string) {
return this.shoppingCardsService.submitPurchase(+id);
}
@Delete(':id')
remove(@Param('id') id: string) {
return this.shoppingCardsService.remove(+id);
}
}

@ -1,26 +0,0 @@
import { Module } from '@nestjs/common';
import { ShoppingCardsService } from './shopping-cards.service';
import { ShoppingCardsController } from './shopping-cards.controller';
import { shoppingCardsProviders } from './shopping-cards.providers';
import { ReceiptsService } from '../receipts/receipts.service';
import { receiptsProviders } from '../receipts/receipts.providers';
import { ProductsService } from '../products/products.service';
import { productsProviders } from '../products/products.providers';
import { OrdersService } from '../orders/orders.service';
import { ordersProviders } from '../orders/orders.providers';
@Module({
controllers: [ShoppingCardsController],
providers: [
ShoppingCardsService,
...shoppingCardsProviders,
ReceiptsService,
...receiptsProviders,
ProductsService,
...productsProviders,
OrdersService,
...ordersProviders,
],
exports: [ShoppingCardsService],
})
export class ShoppingCardsModule {}

@ -1,9 +0,0 @@
import { ShoppingCard } from './entities/shopping-card.entity';
import { SHOPPING_CARD_REPOSITORY } from '../../core/constants';
export const shoppingCardsProviders = [
{
provide: SHOPPING_CARD_REPOSITORY,
useValue: ShoppingCard,
},
];

@ -1,91 +0,0 @@
import { Inject, Injectable } from '@nestjs/common';
import { CreateShoppingCardDto } from './dto/create-shopping-card.dto';
import { UpdateShoppingCardDto } from './dto/update-shopping-card.dto';
import { SHOPPING_CARD_REPOSITORY } from 'src/core/constants';
import { ShoppingCard } from './entities/shopping-card.entity';
import { CreateReceiptDto } from '../receipts/dto';
import { ReceiptsService } from '../receipts/receipts.service';
import { ProductsService } from '../products/products.service';
import { OrdersService } from '../orders/orders.service';
import { CreateOrderDto } from '../orders/dto';
@Injectable()
export class ShoppingCardsService {
constructor(
@Inject(SHOPPING_CARD_REPOSITORY)
private readonly shoppingCardRepository: typeof ShoppingCard,
private readonly receiptService: ReceiptsService,
private readonly productsService: ProductsService,
private readonly ordersService: OrdersService,
) {}
async create(createShoppingCardDto: CreateShoppingCardDto) {
const card = await this.shoppingCardRepository.create(
createShoppingCardDto,
);
for (let p of card.products) {
const [product] = await this.productsService.findOne(p);
card.totalPrice += product.pricePerUnit;
}
return await card.save();
}
async findAll() {
return await this.shoppingCardRepository.findAll();
}
async findbyUser(id: number) {
return await this.shoppingCardRepository.findAll({ where: { userId: id } });
}
async update(id: number, updateShoppingCardDto: UpdateShoppingCardDto) {
const [numberOfAffectedRows, [updatedCard]] =
await this.shoppingCardRepository.update(
{ ...updateShoppingCardDto },
{ where: { userId: id }, returning: true },
);
const [card] = await this.shoppingCardRepository.findAll({
where: { userId: id },
});
card.totalPrice = 0;
for (let p of card.products) {
const [product] = await this.productsService.findOne(p);
card.totalPrice += product.pricePerUnit;
}
return card.save();
}
async remove(id: number) {
return await this.shoppingCardRepository.destroy({ where: { userId: id } });
}
async submitPurchase(id: number) {
const [card] = await this.findbyUser(id);
await this.createReceipt({
userId: id,
products: card.products,
totalPrice: card.totalPrice,
});
await this.remove(id);
const order: CreateOrderDto = {
userId: id,
status: 1,
comments: 'ship asap',
shipperName: 'meti comp',
products: card.products,
};
return await this.ordersService.create(order);
}
private async createReceipt(createReceiptDto: CreateReceiptDto) {
await this.receiptService.create(createReceiptDto);
}
}

@ -1,36 +1,9 @@
import {
IsEmail,
IsEnum,
IsString,
IsNotEmpty,
IsOptional,
} from 'class-validator';
export class CreateUserDto {
@IsNotEmpty()
@IsString()
firstName: string;
@IsNotEmpty()
@IsString()
lastName: string;
@IsNotEmpty()
@IsEmail()
email: string;
@IsNotEmpty()
@IsString()
password: string;
@IsOptional()
@IsString()
phoneNumber: string;
@IsOptional()
@IsEnum(['mail', 'female'])
gender: string;
@IsOptional()
city: string;
}

@ -8,8 +8,6 @@ import {
} from 'sequelize-typescript';
import { Order } from '../../orders/entities/order.entity';
import { Wallet } from 'src/modules/wallets/entities/wallet.entity';
import { Receipt } from 'src/modules/receipts/entities/receipt.entity';
import { ShoppingCard } from 'src/modules/shopping-cards/entities/shopping-card.entity';
@Table({ tableName: 'users' })
export class User extends Model<User> {
@ -69,10 +67,4 @@ export class User extends Model<User> {
@HasOne(() => Wallet)
wallet: Wallet;
@HasOne(() => ShoppingCard)
shoppingCard: ShoppingCard;
@HasMany(() => Receipt)
receipts: Receipt[];
}

@ -1,5 +0,0 @@
export class CreateWalletsTransactionDto {
userId: number;
operation: number;
byAmount: number;
}

@ -1,14 +0,0 @@
import { Table, Column, Model, DataType, HasOne } from 'sequelize-typescript';
import { WalletsTransactions } from './wallets-transaction.entity';
@Table({ tableName: 'transaction_operations', timestamps: false })
export class TransactionOperations extends Model<TransactionOperations> {
@Column({
type: DataType.STRING,
allowNull: false,
})
name: string;
@HasOne(() => WalletsTransactions)
order: WalletsTransactions;
}

@ -1,34 +0,0 @@
import {
Table,
Column,
Model,
DataType,
ForeignKey,
BelongsTo,
} from 'sequelize-typescript';
import { User } from 'src/modules/users/entities/user.entity';
import { TransactionOperations } from './transaction-operation.entity';
@Table({ tableName: 'wallets_transactions', updatedAt: false })
export class WalletsTransactions extends Model<WalletsTransactions> {
@Column({
type: DataType.FLOAT,
allowNull: false,
defaultValue: 0,
})
byAmount: number;
@ForeignKey(() => User)
@Column
userId: number;
@BelongsTo(() => User)
user: User;
@ForeignKey(() => TransactionOperations)
@Column
operation: number;
@BelongsTo(() => TransactionOperations)
transactionOperations: TransactionOperations;
}

@ -1,33 +0,0 @@
import {
Controller,
Get,
Post,
Body,
Patch,
Param,
Delete,
} from '@nestjs/common';
import { WalletsTransactionsService } from './wallets-transactions.service';
import { CreateWalletsTransactionDto } from './dto/create-wallets-transaction.dto';
@Controller('wallets-transactions')
export class WalletsTransactionsController {
constructor(
private readonly walletsTransactionsService: WalletsTransactionsService,
) {}
@Get()
findAll() {
return this.walletsTransactionsService.findAll();
}
@Get(':id')
findOne(@Param('id') id: number) {
return this.walletsTransactionsService.findOne(id);
}
@Get('users/:id')
findByUser(@Param('id') id: number) {
return this.walletsTransactionsService.findByUser(id);
}
}

@ -1,11 +0,0 @@
import { Module } from '@nestjs/common';
import { WalletsTransactionsService } from './wallets-transactions.service';
import { WalletsTransactionsController } from './wallets-transactions.controller';
import { walletsTransactionsProviders } from './wallets-transactions.providers';
@Module({
controllers: [WalletsTransactionsController],
providers: [WalletsTransactionsService, ...walletsTransactionsProviders],
exports: [WalletsTransactionsService],
})
export class WalletsTransactionsModule {}

@ -1,9 +0,0 @@
import { WalletsTransactions } from './entities/wallets-transaction.entity';
import { WALLET_TRANSACTIONS_REPOSITORY } from '../../core/constants';
export const walletsTransactionsProviders = [
{
provide: WALLET_TRANSACTIONS_REPOSITORY,
useValue: WalletsTransactions,
},
];

@ -1,31 +0,0 @@
import { Inject, Injectable } from '@nestjs/common';
import { CreateWalletsTransactionDto } from './dto/create-wallets-transaction.dto';
import { WALLET_TRANSACTIONS_REPOSITORY } from 'src/core/constants';
import { WalletsTransactions } from './entities/wallets-transaction.entity';
@Injectable()
export class WalletsTransactionsService {
constructor(
@Inject(WALLET_TRANSACTIONS_REPOSITORY)
private readonly walletsTransactionsRepository: typeof WalletsTransactions,
) {}
async create(createWalletsTransactionDto: CreateWalletsTransactionDto) {
return await this.walletsTransactionsRepository.create(
createWalletsTransactionDto,
);
}
async findAll() {
return await this.walletsTransactionsRepository.findAll();
}
async findOne(id: number) {
return await this.walletsTransactionsRepository.findAll({ where: { id } });
}
async findByUser(id: number) {
return await this.walletsTransactionsRepository.findAll({
where: { userId: id },
});
}
}

@ -2,20 +2,10 @@ import { Module } from '@nestjs/common';
import { WalletsService } from './wallets.service';
import { WalletsController } from './wallets.controller';
import { walletsProviders } from './wallets.providers';
import { UsersService } from '../users/users.service';
import { WalletsTransactionsModule } from '../wallets-transactions/wallets-transactions.module';
import { UsersModule } from '../users/users.module';
import { usersProviders } from '../users/users.providers';
@Module({
imports: [WalletsTransactionsModule, UsersModule],
controllers: [WalletsController],
providers: [
WalletsService,
UsersService,
...walletsProviders,
...usersProviders,
],
providers: [WalletsService, ...walletsProviders],
exports: [WalletsService],
})
export class WalletsModule {}

@ -4,15 +4,11 @@ import { WALLET_REPOSITORY } from 'src/core/constants';
import { Wallet } from './entities/wallet.entity';
import { User } from '../users/entities/user.entity';
import { UpdateWalletDto } from './dto/update-wallet.dto';
import { WalletsTransactionsService } from '../wallets-transactions/wallets-transactions.service';
import { UsersService } from '../users/users.service';
@Injectable()
export class WalletsService {
constructor(
@Inject(WALLET_REPOSITORY) private readonly walletRepository: typeof Wallet,
private readonly usersService: UsersService,
private readonly walletsTransactionsService: WalletsTransactionsService,
) {}
async getWallet(id: UUID) {
@ -33,9 +29,7 @@ export class WalletsService {
const [wallet] = await this.getWallet(id);
wallet.balance += amount;
await wallet.save();
this.createTransaction(id, 1, amount);
return wallet.save();
}
async withdraw(id: UUID, updateWalletDto: UpdateWalletDto) {
@ -46,23 +40,6 @@ export class WalletsService {
const [wallet] = await this.getWallet(id);
wallet.balance -= amount;
await wallet.save();
this.createTransaction(id, 2, amount);
}
private async createTransaction(
id: UUID,
operation: number,
byAmount: number,
) {
const [user] = await this.usersService.findOne(id);
const transaction = {
operation: operation,
byAmount: byAmount,
userId: user.id,
};
await this.walletsTransactionsService.create(transaction);
return wallet.save();
}
}

Loading…
Cancel
Save