|
| 1 | +diff --git a/src/models/product.model.ts b/src/models/product.model.ts |
| 2 | +index 4b83d65..03d548f 100644 |
| 3 | +--- a/src/models/product.model.ts |
| 4 | ++++ b/src/models/product.model.ts |
| 5 | +@@ -4,12 +4,15 @@ import { UserDocument } from "./user.model"; |
| 6 | + |
| 7 | + const nanoid = customAlphabet("abcdefghijklmnopqrstuvwxyz0123456789", 10); |
| 8 | + |
| 9 | +-export interface ProductDocument extends mongoose.Document { |
| 10 | ++export interface ProductInput { |
| 11 | + user: UserDocument["_id"]; |
| 12 | + title: string; |
| 13 | + description: string; |
| 14 | + price: number; |
| 15 | + image: string; |
| 16 | ++} |
| 17 | ++ |
| 18 | ++export interface ProductDocument extends ProductInput, mongoose.Document { |
| 19 | + createdAt: Date; |
| 20 | + updatedAt: Date; |
| 21 | + } |
| 22 | +diff --git a/src/models/user.model.ts b/src/models/user.model.ts |
| 23 | +index ce6ea8f..37dfbc0 100644 |
| 24 | +--- a/src/models/user.model.ts |
| 25 | ++++ b/src/models/user.model.ts |
| 26 | +@@ -2,10 +2,13 @@ import mongoose from "mongoose"; |
| 27 | + import bcrypt from "bcrypt"; |
| 28 | + import config from "config"; |
| 29 | + |
| 30 | +-export interface UserDocument extends mongoose.Document { |
| 31 | ++export interface UserInput { |
| 32 | + email: string; |
| 33 | + name: string; |
| 34 | + password: string; |
| 35 | ++} |
| 36 | ++ |
| 37 | ++export interface UserDocument extends UserInput, mongoose.Document { |
| 38 | + createdAt: Date; |
| 39 | + updatedAt: Date; |
| 40 | + comparePassword(candidatePassword: string): Promise<Boolean>; |
| 41 | +diff --git a/src/service/product.service.ts b/src/service/product.service.ts |
| 42 | +index 2dad4ca..b382b4b 100644 |
| 43 | +--- a/src/service/product.service.ts |
| 44 | ++++ b/src/service/product.service.ts |
| 45 | +@@ -1,14 +1,10 @@ |
| 46 | +-import { |
| 47 | +- DocumentDefinition, |
| 48 | +- FilterQuery, |
| 49 | +- QueryOptions, |
| 50 | +- UpdateQuery, |
| 51 | +-} from "mongoose"; |
| 52 | +-import ProductModel, { ProductDocument } from "../models/product.model"; |
| 53 | ++import { FilterQuery, QueryOptions, UpdateQuery } from "mongoose"; |
| 54 | ++import ProductModel, { |
| 55 | ++ ProductDocument, |
| 56 | ++ ProductInput, |
| 57 | ++} from "../models/product.model"; |
| 58 | + |
| 59 | +-export async function createProduct( |
| 60 | +- input: DocumentDefinition<Omit<ProductDocument, "createdAt" | "updatedAt">> |
| 61 | +-) { |
| 62 | ++export async function createProduct(input: ProductInput) { |
| 63 | + return ProductModel.create(input); |
| 64 | + } |
| 65 | + |
| 66 | +diff --git a/src/service/user.service.ts b/src/service/user.service.ts |
| 67 | +index 7dee694..af904d0 100644 |
| 68 | +--- a/src/service/user.service.ts |
| 69 | ++++ b/src/service/user.service.ts |
| 70 | +@@ -1,12 +1,8 @@ |
| 71 | +-import { DocumentDefinition, FilterQuery } from "mongoose"; |
| 72 | ++import { FilterQuery } from "mongoose"; |
| 73 | + import { omit } from "lodash"; |
| 74 | +-import UserModel, { UserDocument } from "../models/user.model"; |
| 75 | ++import UserModel, { UserDocument, UserInput } from "../models/user.model"; |
| 76 | + |
| 77 | +-export async function createUser( |
| 78 | +- input: DocumentDefinition< |
| 79 | +- Omit<UserDocument, "createdAt" | "updatedAt" | "comparePassword"> |
| 80 | +- > |
| 81 | +-) { |
| 82 | ++export async function createUser(input: UserInput) { |
| 83 | + try { |
| 84 | + const user = await UserModel.create(input); |
| 85 | + |
0 commit comments