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
fb70fb1e
Commit
fb70fb1e
authored
Apr 22, 2025
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update StringIdBase and DateColumn parser
parent
128a4577
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
14 deletions
+27
-14
src/bases/id-base.ts
src/bases/id-base.ts
+11
-8
src/decorators/property.ts
src/decorators/property.ts
+16
-6
No files found.
src/bases/id-base.ts
View file @
fb70fb1e
...
...
@@ -7,7 +7,7 @@ import {
NotWritable
,
StringColumn
,
}
from
'
../decorators
'
;
import
{
IsNotEmpty
}
from
'
class-validator
'
;
import
{
IsNotEmpty
,
IsString
}
from
'
class-validator
'
;
import
{
MergePropertyDecorators
}
from
'
nesties
'
;
export
interface
IdOptions
{
...
...
@@ -38,7 +38,7 @@ export function IdBase(idOptions: IdOptions = {}) {
}
export
interface
StringIdOptions
extends
IdOptions
{
length
:
number
;
length
?
:
number
;
uuid
?:
boolean
;
}
...
...
@@ -56,18 +56,21 @@ export function StringIdBase(idOptions: StringIdOptions) {
}
};
const
decs
=
[
NotChangeable
(),
StringColumn
(
idOptions
.
length
,
{
StringColumn
(
idOptions
.
length
||
(
idOptions
.
uuid
?
36
:
255
),
{
required
:
!
idOptions
.
uuid
,
description
:
idOptions
.
description
,
columnExtras
:
{
primary
:
true
,
nullable
:
false
},
}),
Reflect
.
metadata
(
'
design:type
'
,
String
),
IsNotEmpty
(),
...(
idOptions
.
uuid
?
[
Generated
(
'
uuid
'
),
NotWritable
(),
]
:
[
IsString
(),
IsNotEmpty
(),
NotChangeable
(),
])
];
if
(
idOptions
.
uuid
)
{
decs
.
push
(
Generated
(
'
uuid
'
));
}
const
dec
=
MergePropertyDecorators
(
decs
);
dec
(
cl
.
prototype
,
'
id
'
);
return
cl
;
...
...
src/decorators/property.ts
View file @
fb70fb1e
...
...
@@ -144,13 +144,23 @@ export const DateColumn = (
IsDate
(),
Transform
(
(
v
)
=>
{
if
(
v
.
value
==
null
)
return
v
.
value
;
if
(
v
.
value
instanceof
Date
)
return
v
.
value
;
if
(
typeof
v
.
value
===
'
number
'
)
return
new
Date
(
v
.
value
*
1000
);
if
(
typeof
v
.
value
===
'
string
'
&&
v
.
value
.
match
(
/^
\d
+$/
))
{
return
new
Date
(
parseInt
(
v
.
value
,
10
)
*
1000
);
const
value
=
v
.
value
;
if
(
value
==
null
||
value
instanceof
Date
)
return
value
;
const
timestampToDate
=
(
t
:
number
,
isSeconds
:
boolean
)
=>
new
Date
(
isSeconds
?
t
*
1000
:
t
);
if
(
typeof
value
===
'
number
'
)
{
const
isSeconds
=
!
Number
.
isInteger
(
value
)
||
value
<
1
e12
;
return
timestampToDate
(
value
,
isSeconds
);
}
return
new
Date
(
v
.
value
);
if
(
typeof
value
===
'
string
'
&&
/^
\d
+
(\.\d
+
)?
$/
.
test
(
value
))
{
const
isSeconds
=
value
.
includes
(
'
.
'
)
||
parseFloat
(
value
)
<
1
e12
;
return
timestampToDate
(
parseFloat
(
value
),
isSeconds
);
}
return
new
Date
(
value
);
// fallback to native parser
},
{
toClassOnly
:
true
,
...
...
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