Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
I
initial_project
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Нұрасыл Қайратұлы
initial_project
Commits
f54153c9
Commit
f54153c9
authored
Aug 22, 2024
by
Нұрасыл Қайратұлы
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updt
parent
41941888
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
270 additions
and
61 deletions
+270
-61
products.json
server/data/products.json
+0
-54
package-lock.json
server/package-lock.json
+183
-1
package.json
server/package.json
+5
-2
appDataSource.ts
server/src/appDataSource.ts
+13
-4
category.factory.ts
server/src/database/factories/category.factory.ts
+10
-0
product.factory.ts
server/src/database/factories/product.factory.ts
+11
-0
user.factory.ts
server/src/database/factories/user.factory.ts
+13
-0
init.seeds.ts
server/src/database/init.seeds.ts
+8
-0
main.seeds.ts
server/src/database/seeds/main.seeds.ts
+21
-0
user.entity.ts
server/src/entities/user.entity.ts
+6
-0
No files found.
server/data/products.json
deleted
100644 → 0
View file @
41941888
[
{
"title"
:
"Lorem ipsum"
,
"description"
:
"Dolor si amet"
,
"price"
:
500
,
"id"
:
"0.9133269846292313"
},
{
"title"
:
"Lorem ipsum 2"
,
"description"
:
"Dolor si amet"
,
"price"
:
500
,
"id"
:
"0.09792516360811865"
},
{
"title"
:
"Lorem ipsum 3"
,
"description"
:
"Dolor si amet"
,
"price"
:
500
,
"id"
:
"0.5230269041392861"
},
{
"description"
:
"Ideal for a zombie"
,
"price"
:
"687645"
,
"title"
:
"Griffiths-grr"
,
"id"
:
"0.7259402088168749"
},
{
"description"
:
"asdasd"
,
"price"
:
"0222"
,
"title"
:
"test"
,
"image"
:
""
,
"id"
:
"0.30067479554039167"
},
{
"description"
:
"ssss"
,
"price"
:
"0333"
,
"title"
:
"sss"
,
"image"
:
""
,
"id"
:
"0.8912701822634759"
},
{
"description"
:
"fffffffffff"
,
"price"
:
"022222"
,
"title"
:
"fffffffffff"
,
"image"
:
"169fc2c0-e96f-4971-9cb6-480c6a39362e.jpeg"
,
"id"
:
"0.2281329580756415"
},
{
"description"
:
"aaaaaaaaaaaaaaa"
,
"price"
:
"022"
,
"title"
:
"aaaaaaaaaaaaaa"
,
"image"
:
"e6d98dfa-d11a-4381-a4df-1cd5730b6afe.jpeg"
,
"id"
:
"0.7119914504529552"
}
]
\ No newline at end of file
server/package-lock.json
View file @
f54153c9
This diff is collapsed.
Click to expand it.
server/package.json
View file @
f54153c9
...
@@ -7,7 +7,8 @@
...
@@ -7,7 +7,8 @@
"test"
:
"echo
\"
Error: no test specified
\"
&& exit 1"
,
"test"
:
"echo
\"
Error: no test specified
\"
&& exit 1"
,
"dev"
:
"nodemon"
,
"dev"
:
"nodemon"
,
"lint"
:
"eslint"
,
"lint"
:
"eslint"
,
"lint:fix"
:
"eslint --fix"
"lint:fix"
:
"eslint --fix"
,
"seed"
:
"node -r tsconfig-paths/register -r ts-node/register src/database/init.seeds.ts"
},
},
"keywords"
:
[],
"keywords"
:
[],
"author"
:
""
,
"author"
:
""
,
...
@@ -34,6 +35,7 @@
...
@@ -34,6 +35,7 @@
"typescript"
:
"^5.1.6"
"typescript"
:
"^5.1.6"
},
},
"devDependencies"
:
{
"devDependencies"
:
{
"@faker-js/faker"
:
"^8.4.1"
,
"@types/bcrypt"
:
"^5.0.2"
,
"@types/bcrypt"
:
"^5.0.2"
,
"@types/cors"
:
"^2.8.17"
,
"@types/cors"
:
"^2.8.17"
,
"@types/express"
:
"^4.17.17"
,
"@types/express"
:
"^4.17.17"
,
...
@@ -45,6 +47,7 @@
...
@@ -45,6 +47,7 @@
"eslint-plugin-prettier"
:
"^5.0.0"
,
"eslint-plugin-prettier"
:
"^5.0.0"
,
"nodemon"
:
"^3.0.1"
,
"nodemon"
:
"^3.0.1"
,
"prettier"
:
"^3.0.0"
,
"prettier"
:
"^3.0.0"
,
"tsconfig-paths"
:
"^4.2.0"
"tsconfig-paths"
:
"^4.2.0"
,
"typeorm-extension"
:
"^3.6.1"
}
}
}
}
server/src/appDataSource.ts
View file @
f54153c9
import
{
DataSource
}
from
"typeorm"
;
import
{
DataSource
,
DataSourceOptions
}
from
"typeorm"
;
import
{
Product
}
from
"./entities/product.entity"
;
import
{
Product
}
from
"./entities/product.entity"
;
import
{
Category
}
from
"./entities/category.entity"
;
import
{
Category
}
from
"./entities/category.entity"
;
import
{
User
}
from
"./entities/user.entity"
;
import
{
User
}
from
"./entities/user.entity"
;
import
{
UserFactory
}
from
"./database/factories/user.factory"
;
import
{
SeederOptions
}
from
"typeorm-extension"
;
import
{
CategoryFactory
}
from
"./database/factories/category.factory"
;
import
{
ProductFactory
}
from
"./database/factories/product.factory"
;
import
MainSeeder
from
"./database/seeds/main.seeds"
;
export
const
AppDataSource
=
new
DataSource
(
{
const
options
:
DataSourceOptions
&
SeederOptions
=
{
type
:
"postgres"
,
type
:
"postgres"
,
host
:
"localhost"
,
host
:
"localhost"
,
port
:
5432
,
port
:
5432
,
...
@@ -12,5 +17,9 @@ export const AppDataSource = new DataSource({
...
@@ -12,5 +17,9 @@ export const AppDataSource = new DataSource({
database
:
"postgres"
,
database
:
"postgres"
,
schema
:
"public"
,
schema
:
"public"
,
synchronize
:
true
,
synchronize
:
true
,
entities
:
[
Product
,
Category
,
User
]
entities
:
[
Product
,
Category
,
User
],
})
factories
:
[
UserFactory
,
CategoryFactory
,
ProductFactory
],
\ No newline at end of file
seeds
:
[
MainSeeder
]
}
export
const
AppDataSource
=
new
DataSource
(
options
)
\ No newline at end of file
server/src/database/factories/category.factory.ts
0 → 100644
View file @
f54153c9
import
{
Category
}
from
'@/entities/category.entity'
;
import
{
Faker
}
from
'@faker-js/faker'
;
import
{
setSeederFactory
}
from
'typeorm-extension'
;
export
const
CategoryFactory
=
setSeederFactory
(
Category
,
(
faker
:
Faker
)
=>
{
const
category
=
new
Category
()
category
.
title
=
faker
.
commerce
.
department
()
category
.
description
=
faker
.
lorem
.
sentence
()
return
category
})
\ No newline at end of file
server/src/database/factories/product.factory.ts
0 → 100644
View file @
f54153c9
import
{
Product
}
from
'@/entities/product.entity'
;
import
{
Faker
}
from
'@faker-js/faker'
;
import
{
setSeederFactory
}
from
'typeorm-extension'
;
export
const
ProductFactory
=
setSeederFactory
(
Product
,
(
faker
:
Faker
)
=>
{
const
product
=
new
Product
()
product
.
title
=
faker
.
commerce
.
productName
()
product
.
price
=
faker
.
number
.
int
({
min
:
100
,
max
:
2000
})
product
.
description
=
faker
.
lorem
.
sentence
()
return
product
})
\ No newline at end of file
server/src/database/factories/user.factory.ts
0 → 100644
View file @
f54153c9
import
{
User
}
from
"@/entities/user.entity"
;
import
{
Faker
}
from
'@faker-js/faker'
;
import
{
setSeederFactory
}
from
'typeorm-extension'
;
export
const
UserFactory
=
setSeederFactory
(
User
,
async
(
faker
:
Faker
)
=>
{
const
user
=
new
User
()
user
.
username
=
faker
.
internet
.
userName
()
user
.
displayName
=
faker
.
internet
.
displayName
()
user
.
password
=
'test'
await
user
.
hashPassword
()
user
.
generateToken
()
return
user
})
\ No newline at end of file
server/src/database/init.seeds.ts
0 → 100644
View file @
f54153c9
import
{
runSeeders
}
from
"typeorm-extension"
;
import
{
AppDataSource
}
from
"@/appDataSource"
;
AppDataSource
.
initialize
().
then
(
async
()
=>
{
await
AppDataSource
.
synchronize
(
true
)
await
runSeeders
(
AppDataSource
)
process
.
exit
()
})
\ No newline at end of file
server/src/database/seeds/main.seeds.ts
0 → 100644
View file @
f54153c9
import
{
User
}
from
"@/entities/user.entity"
;
import
{
Category
}
from
"@/entities/category.entity"
;
import
{
Product
}
from
"@/entities/product.entity"
;
import
{
DataSource
}
from
"typeorm"
;
import
{
faker
}
from
'@faker-js/faker'
;
import
{
Seeder
,
SeederFactoryManager
}
from
"typeorm-extension"
;
export
default
class
MainSeeder
implements
Seeder
{
public
async
run
(
dataSource
:
DataSource
,
factoryManager
:
SeederFactoryManager
):
Promise
<
any
>
{
const
userFactory
=
factoryManager
.
get
(
User
)
const
categoryFactory
=
factoryManager
.
get
(
Category
)
const
productFactory
=
factoryManager
.
get
(
Product
)
await
userFactory
.
saveMany
(
10
)
const
categories
=
await
categoryFactory
.
saveMany
(
3
)
await
productFactory
.
saveMany
(
4
,
{
category
:
faker
.
helpers
.
arrayElement
(
categories
)
})
await
productFactory
.
saveMany
(
4
,
{
category
:
faker
.
helpers
.
arrayElement
(
categories
)
})
await
productFactory
.
saveMany
(
4
,
{
category
:
faker
.
helpers
.
arrayElement
(
categories
)
})
}
}
\ No newline at end of file
server/src/entities/user.entity.ts
View file @
f54153c9
import
{
Entity
,
PrimaryGeneratedColumn
,
Column
,
Unique
}
from
"typeorm"
;
import
{
Entity
,
PrimaryGeneratedColumn
,
Column
,
Unique
}
from
"typeorm"
;
import
bcrypt
from
'bcrypt'
;
import
bcrypt
from
'bcrypt'
;
const
SALT_WORK_FACTOR
=
10
;
@
Entity
()
@
Entity
()
@
Unique
([
'username'
])
@
Unique
([
'username'
])
export
class
User
{
export
class
User
{
...
@@ -23,6 +24,11 @@ export class User {
...
@@ -23,6 +24,11 @@ export class User {
return
await
bcrypt
.
compare
(
password
,
this
.
password
);
return
await
bcrypt
.
compare
(
password
,
this
.
password
);
}
}
async
hashPassword
()
{
const
salt
=
await
bcrypt
.
genSalt
(
SALT_WORK_FACTOR
)
this
.
password
=
await
bcrypt
.
hash
(
this
.
password
,
salt
)
}
generateToken
()
{
generateToken
()
{
this
.
token
=
crypto
.
randomUUID
();
this
.
token
=
crypto
.
randomUUID
();
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment