Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task 9 #21

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: cart.service, remove unused deps
AlexanderSUS committed Jul 23, 2024
commit 1a29ca24a1f366f940d626476bb5c9fe4a8c201e
16 changes: 1 addition & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -33,8 +33,7 @@
"passport-jwt": "^4.0.1",
"passport-local": "^1.0.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1",
"uuid": "^9.0.0"
"rxjs": "^7.8.1"
},
"devDependencies": {
"@nestjs/cli": "^10.0.3",
2 changes: 1 addition & 1 deletion src/cart/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
enum CartStatuses {
export enum CartStatuses {
OPEN = 'OPEN',
STATUS = 'STATUS',
}
23 changes: 17 additions & 6 deletions src/cart/services/cart.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { Injectable } from '@nestjs/common';
import { randomUUID } from 'crypto';

import { v4 } from 'uuid';
import { Cart, CartStatuses } from '../models';

import { Cart } from '../models';
function getDate(date = new Date()) {
date.setHours(0);
date.setMinutes(0);
date.setMinutes(0);
date.setMilliseconds(0);

return (date.getTime() / 1000).toString();
}

@Injectable()
export class CartService {
@@ -12,14 +20,17 @@ export class CartService {
return this.userCarts[userId];
}

createByUserId(userId: string) {
const id = v4();
createByUserId(user_id: string): Cart {
const userCart = {
id,
id: randomUUID(),
user_id,
created_at: getDate(),
updated_at: getDate(),
status: CartStatuses.OPEN,
items: [],
};

this.userCarts[userId] = userCart;
this.userCarts[user_id] = userCart;

return userCart;
}
4 changes: 2 additions & 2 deletions src/order/services/order.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@nestjs/common';
import { v4 } from 'uuid';
import { randomUUID } from 'crypto';

import { Order } from '../models';

@@ -12,7 +12,7 @@ export class OrderService {
}

create(data: any) {
const id = v4();
const id = randomUUID();
const order = {
...data,
id,
6 changes: 2 additions & 4 deletions src/users/services/users.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Injectable } from '@nestjs/common';

import { v4 } from 'uuid';

import { randomUUID } from 'crypto';
import { User } from '../models';

@Injectable()
@@ -17,7 +15,7 @@ export class UsersService {
}

createOne({ name, password }: User): User {
const id = v4();
const id = randomUUID();
const newUser = { id: name || id, name, password };

this.users[id] = newUser;