Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
nicot
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
3rdeye
nicot
Commits
97618751
Commit
97618751
authored
Jul 15, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move class to fix error
parent
073542e8
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
73 additions
and
29 deletions
+73
-29
src/bases/index.ts
src/bases/index.ts
+1
-0
src/bases/page-settings.ts
src/bases/page-settings.ts
+0
-0
src/bases/time-base.ts
src/bases/time-base.ts
+1
-1
src/crud-base.ts
src/crud-base.ts
+21
-6
src/dto/index.ts
src/dto/index.ts
+1
-1
src/dto/return-message.ts
src/dto/return-message.ts
+1
-1
tests/sample.spec.ts
tests/sample.spec.ts
+48
-20
No files found.
src/bases/index.ts
View file @
97618751
export
*
from
'
./time-base
'
;
export
*
from
'
./id-base
'
;
export
*
from
'
./page-settings
'
;
src/
dto
/page-settings.ts
→
src/
bases
/page-settings.ts
View file @
97618751
File moved
src/bases/time-base.ts
View file @
97618751
import
{
CreateDateColumn
,
DeleteDateColumn
,
UpdateDateColumn
}
from
'
typeorm
'
;
import
{
PageSettingsDto
}
from
'
../dto
'
;
import
{
NotColumn
}
from
'
../decorators
'
;
import
{
PageSettingsDto
}
from
'
./page-settings
'
;
export
interface
DeletionWise
{
deleteTime
?:
Date
;
...
...
src/crud-base.ts
View file @
97618751
import
{
BlankReturnMessageDto
,
PageSettingsFactory
,
ImportEntryDto
,
PaginatedReturnMessageDto
,
QueryWise
,
ReturnMessageDto
,
}
from
'
./dto
'
;
import
{
...
...
@@ -13,7 +12,12 @@ import {
SelectQueryBuilder
,
UpdateResult
,
}
from
'
typeorm
'
;
import
{
DeletionWise
,
ImportWise
}
from
'
./bases
'
;
import
{
DeletionWise
,
ImportWise
,
PageSettingsFactory
,
QueryWise
,
}
from
'
./bases
'
;
import
{
ImportEntry
}
from
'
./dto/import-entry
'
;
import
{
ConsoleLogger
}
from
'
@nestjs/common
'
;
import
{
camelCase
}
from
'
typeorm/util/StringUtils
'
;
...
...
@@ -46,6 +50,8 @@ export interface CrudOptions<T extends ValidCrudEntity<T>> {
export
class
CrudBase
<
T
extends
ValidCrudEntity
<
T
>>
{
readonly
entityName
=
this
.
entityClass
.
name
;
readonly
entityReturnMessageDto
=
ReturnMessageDto
(
this
.
entityClass
);
readonly
importEntryDto
=
ImportEntryDto
(
this
.
entityClass
);
readonly
importReturnMessageDto
=
ReturnMessageDto
([
this
.
importEntryDto
]);
readonly
entityPaginatedReturnMessageDto
=
PaginatedReturnMessageDto
(
this
.
entityClass
,
);
...
...
@@ -69,7 +75,7 @@ export class CrudBase<T extends ValidCrudEntity<T>> {
skipErrors
=
false
,
)
{
const
entsWithId
=
ents
.
filter
((
ent
)
=>
ent
.
id
!=
null
);
return
await
this
.
repo
.
manager
.
transaction
(
async
(
mdb
)
=>
{
const
result
=
await
this
.
repo
.
manager
.
transaction
(
async
(
mdb
)
=>
{
let
skipped
:
{
result
:
string
;
entry
:
T
}[]
=
[];
const
repo
=
mdb
.
getRepository
(
this
.
entityClass
);
...
...
@@ -130,6 +136,7 @@ export class CrudBase<T extends ValidCrudEntity<T>> {
throw
new
BlankReturnMessageDto
(
500
,
'
internal error
'
).
toException
();
}
});
return
result
;
}
async
create
(
ent
:
T
,
beforeCreate
?:
(
repo
:
Repository
<
T
>
)
=>
Promise
<
void
>
)
{
...
...
@@ -324,7 +331,7 @@ export class CrudBase<T extends ValidCrudEntity<T>> {
async
importEntities
(
ents
:
T
[],
extraChecking
?:
(
ent
:
T
)
=>
string
|
Promise
<
string
>
,
)
:
Promise
<
ImportEntry
<
T
>
[]
>
{
)
{
const
invalidResults
=
_
.
compact
(
await
Promise
.
all
(
ents
.
map
(
async
(
ent
)
=>
{
...
...
@@ -356,7 +363,15 @@ export class CrudBase<T extends ValidCrudEntity<T>> {
...
data
.
skipped
,
...
data
.
results
.
map
((
e
)
=>
({
entry
:
e
,
result
:
'
OK
'
})),
];
return
results
;
return
new
this
.
importReturnMessageDto
(
201
,
'
success
'
,
results
.
map
((
r
)
=>
{
const
entry
=
new
this
.
importEntryDto
();
Object
.
assign
(
entry
,
r
);
return
entry
;
}),
);
}
async
exists
(
id
:
EntityId
<
T
>
):
Promise
<
boolean
>
{
...
...
src/dto/index.ts
View file @
97618751
export
*
from
'
./page-settings
'
;
export
*
from
'
./return-message
'
;
export
*
from
'
./import-entry
'
;
src/dto/return-message.ts
View file @
97618751
import
{
ApiProperty
}
from
'
@nestjs/swagger
'
;
import
{
HttpException
}
from
'
@nestjs/common
'
;
import
{
PageSettingsWise
}
from
'
./page-settings
'
;
import
{
PageSettingsWise
}
from
'
.
./bases
/page-settings
'
;
import
{
AnyClass
,
ClassOrArray
,
...
...
tests/sample.spec.ts
View file @
97618751
import
{
Index
}
from
'
typeorm
'
;
import
{
plainToInstance
}
from
'
class-transformer
'
;
import
{
EnumColumn
,
IntColumn
,
StringColumn
}
from
'
../src/decorators
'
;
import
{
IdBase
}
from
'
../src/bases
'
;
import
{
validate
}
from
'
class-validator
'
;
import
{
EnumColumn
,
IntColumn
,
StringColumn
,
IdBase
,
StringIdBase
}
from
'
..
'
;
import
{
validateSync
}
from
'
class-validator
'
;
enum
Gender
{
F
=
'
F
'
,
...
...
@@ -23,27 +22,56 @@ class User extends IdBase() {
gender
:
Gender
;
}
class
User2
extends
StringIdBase
({
length
:
20
})
{
@
Index
()
@
StringColumn
(
5
,
{
required
:
true
,
})
name
:
string
;
@
IntColumn
(
'
int
'
,
{
unsigned
:
true
})
age
:
number
;
@
EnumColumn
(
Gender
)
gender
:
Gender
;
}
describe
(
'
nicot
'
,
()
=>
{
it
(
'
create entity class
'
,
()
=>
{
const
good1
=
plainToInstance
(
User
,
{
name
:
'
John
'
,
age
:
20
});
const
good2
=
plainToInstance
(
User
,
{
it
(
'
creates entity class
'
,
()
=>
{
expect
(
validateSync
(
plainToInstance
(
User
,
{
name
:
'
John
'
,
age
:
20
})),
).
toEqual
([]);
expect
(
validateSync
(
plainToInstance
(
User
,
{
name
:
'
John
'
,
age
:
20
,
gender
:
Gender
.
M
}),
),
).
toEqual
([]);
expect
(
validateSync
(
plainToInstance
(
User
,
{
name
:
'
John111
'
,
age
:
20
})),
).
not
.
toEqual
([]);
expect
(
validateSync
(
plainToInstance
(
User
,
{
age
:
20
}))).
not
.
toEqual
([]);
expect
(
validateSync
(
plainToInstance
(
User
,
{
name
:
'
John
'
,
age
:
-
1
})),
).
not
.
toEqual
([]);
expect
(
validateSync
(
plainToInstance
(
User
,
{
name
:
'
John
'
,
age
:
20
,
gender
:
'
foo
'
}),
),
).
not
.
toEqual
([]);
});
it
(
'
creates entity class with string id
'
,
()
=>
{
const
user2
=
plainToInstance
(
User2
,
{
name
:
'
John
'
,
age
:
20
,
gender
:
Gender
.
M
,
});
const
bad1
=
plainToInstance
(
User
,
{
name
:
'
John111
'
,
age
:
20
});
const
bad2
=
plainToInstance
(
User
,
{
age
:
20
});
const
bad3
=
plainToInstance
(
User
,
{
name
:
'
John
'
,
age
:
-
1
});
const
bad4
=
plainToInstance
(
User
,
{
name
:
'
John
'
,
age
:
20
,
gender
:
'
foo
'
,
});
expect
(
validate
(
good1
)).
resolves
.
toEqual
([]);
expect
(
validate
(
good2
)).
resolves
.
toEqual
([]);
expect
(
validate
(
bad1
)).
resolves
.
not
.
toEqual
([]);
expect
(
validate
(
bad2
)).
resolves
.
not
.
toEqual
([]);
expect
(
validate
(
bad3
)).
resolves
.
not
.
toEqual
([]);
expect
(
validate
(
bad4
)).
resolves
.
not
.
toEqual
([]);
user2
.
id
=
'
join111
'
;
expect
(
validateSync
(
user2
)).
toEqual
([]);
expect
(
validateSync
(
plainToInstance
(
User2
,
{
name
:
'
John
'
,
age
:
20
,
gender
:
Gender
.
M
}),
),
).
not
.
toEqual
([]);
});
});
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