Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
taobao-mini-template
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
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
qinhaitao
taobao-mini-template
Commits
1f54aff7
Commit
1f54aff7
authored
Aug 20, 2020
by
qinhaitao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 保存接口
parent
e49cd988
Changes
15
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
225 additions
and
46 deletions
+225
-46
save.controller.js
server/duibats/dist/controller/save.controller.js
+3
-10
save.controller.js.map
server/duibats/dist/controller/save.controller.js.map
+1
-1
validate.d.ts
server/duibats/dist/decorator/validate.d.ts
+2
-1
validate.js
server/duibats/dist/decorator/validate.js
+72
-4
validate.js.map
server/duibats/dist/decorator/validate.js.map
+1
-1
index.js
server/duibats/dist/index.js
+3
-1
index.js.map
server/duibats/dist/index.js.map
+1
-1
saveValidate.d.ts
server/duibats/dist/utils/saveValidate.d.ts
+2
-3
saveValidate.js
server/duibats/dist/utils/saveValidate.js
+60
-3
saveValidate.js.map
server/duibats/dist/utils/saveValidate.js.map
+1
-1
server.js
server/duibats/mockServer/server.js
+3
-4
save.controller.ts
server/duibats/src/controller/save.controller.ts
+3
-12
validate.ts
server/duibats/src/decorator/validate.ts
+24
-3
index.ts
server/duibats/src/index.ts
+3
-1
saveValidate.ts
server/duibats/src/utils/saveValidate.ts
+46
-0
No files found.
server/duibats/dist/controller/save.controller.js
View file @
1f54aff7
...
...
@@ -48,19 +48,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
var
decorator_1
=
require
(
"../decorator"
);
var
service_1
=
require
(
"../service"
);
// const activityValidate: <T><RuleItem> = {
// title: {
// require: true,
// type: 'string',
// validator: (rule, value, callback, data) => {}
// }
// }
var
saveValidate_1
=
require
(
"../utils/saveValidate"
);
var
ActivitSaveController
=
/** @class */
(
function
()
{
function
ActivitSaveController
()
{
}
/**
* 保存活动
*/
// @paramsCheck(['title', 'startTime', 'endTime', 'tasks', 'rule'])
ActivitSaveController
.
prototype
.
saveActivityInfo
=
function
(
context
,
_a
,
_b
)
{
var
activityconfigService
=
_b
[
0
];
return
__awaiter
(
this
,
void
0
,
void
0
,
function
()
{
...
...
@@ -81,9 +76,7 @@ var ActivitSaveController = /** @class */ (function () {
});
};
__decorate
([
decorator_1
.
paramsCheck
([
'title'
,
'startTime'
,
'endTime'
,
'tasks'
,
'rule'
])
// @paramsValidate(activityValidate)
,
decorator_1
.
paramsValidate
(
saveValidate_1
.
saveParams
),
decorator_1
.
services
([
service_1
.
ActivityconfigService
]),
__metadata
(
"design:type"
,
Function
),
__metadata
(
"design:paramtypes"
,
[
Object
,
Object
,
Array
]),
...
...
server/duibats/dist/controller/save.controller.js.map
View file @
1f54aff7
{"version":3,"file":"save.controller.js","sourceRoot":"","sources":["../../src/controller/save.controller.ts"],"names":[],"mappings":";AAAA,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGd,0CAAoE;AAEpE,sCAAkD;AAclD,4CAA4C;AAC5C,aAAa;AACb,qBAAqB;AACrB,sBAAsB;AACtB,qDAAqD;AACrD,MAAM;AACN,IAAI;AAEJ;IAAA;IAiBA,CAAC;IAhBC;;OAEG;IAIG,gDAAgB,GAAtB,UAAuB,OAA6B,EAAE,EAAE,EAAE,EAAgD;YAA/C,qBAAqB,QAAA;;;;;;wBACxE,KAAwE,OAAO,CAAC,IAAI,EAAlF,aAAU,EAAV,KAAK,mBAAG,EAAE,KAAA,EAAE,kBAAe,EAAf,UAAU,mBAAG,EAAE,KAAA,EAAE,SAAS,eAAA,EAAE,OAAO,aAAA,EAAE,aAAU,EAAV,KAAK,mBAAG,EAAE,KAAA,EAAE,IAAI,UAAA,CAAiB;wBAEpF,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;6BAGtB,UAAU,EAAV,wBAAU;wBACE,qBAAM,qBAAqB,CAAC,2BAA2B,CAAC,UAAU,CAAC,EAAA;;wBAAjF,WAAW,GAAG,SAAmE,CAAA;;;;;;KAEpF;IATD;QAHC,uBAAW,CAAC,CAAC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAChE,oCAAoC;;QACnC,oBAAQ,CAAC,CAAC,+BAAqB,CAAC,CAAC;;;;iEAUjC;IACH,4BAAC;CAAA,AAjBD,IAiBC;kBAjBoB,qBAAqB"}
\ No newline at end of file
{"version":3,"file":"save.controller.js","sourceRoot":"","sources":["../../src/controller/save.controller.ts"],"names":[],"mappings":";AAAA,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGd,0CAAoE;AAEpE,sCAAkD;AAClD,sDAAkD;AAYlD;IAAA;IAiBA,CAAC;IAhBC;;OAEG;IACH,mEAAmE;IAG7D,gDAAgB,GAAtB,UAAuB,OAA6B,EAAE,EAAE,EAAE,EAAgD;YAA/C,qBAAqB,QAAA;;;;;;wBACxE,KAAwE,OAAO,CAAC,IAAI,EAAlF,aAAU,EAAV,KAAK,mBAAG,EAAE,KAAA,EAAE,kBAAe,EAAf,UAAU,mBAAG,EAAE,KAAA,EAAE,SAAS,eAAA,EAAE,OAAO,aAAA,EAAE,aAAU,EAAV,KAAK,mBAAG,EAAE,KAAA,EAAE,IAAI,UAAA,CAAiB;wBAEpF,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;6BAGtB,UAAU,EAAV,wBAAU;wBACE,qBAAM,qBAAqB,CAAC,2BAA2B,CAAC,UAAU,CAAC,EAAA;;wBAAjF,WAAW,GAAG,SAAmE,CAAA;;;;;;KAEpF;IATD;QAFC,0BAAc,CAAC,yBAAU,CAAC;QAC1B,oBAAQ,CAAC,CAAC,+BAAqB,CAAC,CAAC;;;;iEAUjC;IACH,4BAAC;CAAA,AAjBD,IAiBC;kBAjBoB,qBAAqB"}
\ No newline at end of file
server/duibats/dist/decorator/validate.d.ts
View file @
1f54aff7
export
declare
const
paramsValidate
:
(
validator
:
object
)
=>
(
target
:
Object
,
name
:
string
,
descriptor
:
PropertyDescriptor
)
=>
void
;
import
{
Rules
}
from
'async-validator'
;
export
declare
const
paramsValidate
:
(
validators
:
Rules
)
=>
(
target
:
Object
,
name
:
string
,
descriptor
:
PropertyDescriptor
)
=>
void
;
server/duibats/dist/decorator/validate.js
View file @
1f54aff7
...
...
@@ -10,20 +10,88 @@ var __assign = (this && this.__assign) || function () {
};
return
__assign
.
apply
(
this
,
arguments
);
};
var
__awaiter
=
(
this
&&
this
.
__awaiter
)
||
function
(
thisArg
,
_arguments
,
P
,
generator
)
{
function
adopt
(
value
)
{
return
value
instanceof
P
?
value
:
new
P
(
function
(
resolve
)
{
resolve
(
value
);
});
}
return
new
(
P
||
(
P
=
Promise
))(
function
(
resolve
,
reject
)
{
function
fulfilled
(
value
)
{
try
{
step
(
generator
.
next
(
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
rejected
(
value
)
{
try
{
step
(
generator
[
"throw"
](
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
step
(
result
)
{
result
.
done
?
resolve
(
result
.
value
)
:
adopt
(
result
.
value
).
then
(
fulfilled
,
rejected
);
}
step
((
generator
=
generator
.
apply
(
thisArg
,
_arguments
||
[])).
next
());
});
};
var
__generator
=
(
this
&&
this
.
__generator
)
||
function
(
thisArg
,
body
)
{
var
_
=
{
label
:
0
,
sent
:
function
()
{
if
(
t
[
0
]
&
1
)
throw
t
[
1
];
return
t
[
1
];
},
trys
:
[],
ops
:
[]
},
f
,
y
,
t
,
g
;
return
g
=
{
next
:
verb
(
0
),
"throw"
:
verb
(
1
),
"return"
:
verb
(
2
)
},
typeof
Symbol
===
"function"
&&
(
g
[
Symbol
.
iterator
]
=
function
()
{
return
this
;
}),
g
;
function
verb
(
n
)
{
return
function
(
v
)
{
return
step
([
n
,
v
]);
};
}
function
step
(
op
)
{
if
(
f
)
throw
new
TypeError
(
"Generator is already executing."
);
while
(
_
)
try
{
if
(
f
=
1
,
y
&&
(
t
=
op
[
0
]
&
2
?
y
[
"return"
]
:
op
[
0
]
?
y
[
"throw"
]
||
((
t
=
y
[
"return"
])
&&
t
.
call
(
y
),
0
)
:
y
.
next
)
&&
!
(
t
=
t
.
call
(
y
,
op
[
1
])).
done
)
return
t
;
if
(
y
=
0
,
t
)
op
=
[
op
[
0
]
&
2
,
t
.
value
];
switch
(
op
[
0
])
{
case
0
:
case
1
:
t
=
op
;
break
;
case
4
:
_
.
label
++
;
return
{
value
:
op
[
1
],
done
:
false
};
case
5
:
_
.
label
++
;
y
=
op
[
1
];
op
=
[
0
];
continue
;
case
7
:
op
=
_
.
ops
.
pop
();
_
.
trys
.
pop
();
continue
;
default
:
if
(
!
(
t
=
_
.
trys
,
t
=
t
.
length
>
0
&&
t
[
t
.
length
-
1
])
&&
(
op
[
0
]
===
6
||
op
[
0
]
===
2
))
{
_
=
0
;
continue
;
}
if
(
op
[
0
]
===
3
&&
(
!
t
||
(
op
[
1
]
>
t
[
0
]
&&
op
[
1
]
<
t
[
3
])))
{
_
.
label
=
op
[
1
];
break
;
}
if
(
op
[
0
]
===
6
&&
_
.
label
<
t
[
1
])
{
_
.
label
=
t
[
1
];
t
=
op
;
break
;
}
if
(
t
&&
_
.
label
<
t
[
2
])
{
_
.
label
=
t
[
2
];
_
.
ops
.
push
(
op
);
break
;
}
if
(
t
[
2
])
_
.
ops
.
pop
();
_
.
trys
.
pop
();
continue
;
}
op
=
body
.
call
(
thisArg
,
_
);
}
catch
(
e
)
{
op
=
[
6
,
e
];
y
=
0
;
}
finally
{
f
=
t
=
0
;
}
if
(
op
[
0
]
&
5
)
throw
op
[
1
];
return
{
value
:
op
[
0
]
?
op
[
1
]
:
void
0
,
done
:
true
};
}
};
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
exports
.
paramsValidate
=
void
0
;
exports
.
paramsValidate
=
function
(
validator
)
{
/** @format */
var
sdk_1
=
require
(
"../sdk"
);
var
constants_1
=
require
(
"../constants"
);
var
async_validator_1
=
require
(
"async-validator"
);
exports
.
paramsValidate
=
function
(
validators
)
{
return
function
(
target
,
name
,
descriptor
)
{
var
method
=
descriptor
.
value
;
descriptor
.
value
=
function
()
{
var
_a
;
var
args
=
[];
for
(
var
_i
=
0
;
_i
<
arguments
.
length
;
_i
++
)
{
args
[
_i
]
=
arguments
[
_i
];
}
var
context
=
args
[
0
],
_a
=
args
[
1
],
otherArgs
=
_a
===
void
0
?
{}
:
_a
;
var
params
=
Object
.
keys
(
context
.
data
);
return
method
.
apply
(
target
,
[
context
,
__assign
({},
otherArgs
)]);
return
__awaiter
(
this
,
void
0
,
void
0
,
function
()
{
var
context
,
_b
,
otherArgs
,
errors
;
return
__generator
(
this
,
function
(
_c
)
{
switch
(
_c
.
label
)
{
case
0
:
context
=
args
[
0
],
_b
=
args
[
1
],
otherArgs
=
_b
===
void
0
?
{}
:
_b
;
return
[
4
/*yield*/
,
validateParams
(
validators
,
context
.
data
)];
case
1
:
errors
=
(
_c
.
sent
()).
errors
;
console
.
log
(
errors
);
if
(
errors
)
return
[
2
/*return*/
,
sdk_1
.
resultsModel
.
error
(
constants_1
.
CODE_TYPES
.
SYSTEM_ERROR
,
(
_a
=
errors
===
null
||
errors
===
void
0
?
void
0
:
errors
[
0
])
===
null
||
_a
===
void
0
?
void
0
:
_a
.
message
)];
return
[
2
/*return*/
,
method
.
apply
(
target
,
[
context
,
__assign
({},
otherArgs
)])];
}
});
});
};
};
};
var
validateParams
=
function
(
validators
,
data
)
{
var
validator
=
new
async_validator_1
.
default
(
validators
);
return
new
Promise
(
function
(
resolve
)
{
validator
.
validate
(
data
)
.
then
(
function
()
{
resolve
({});
})
.
catch
(
function
(
_a
)
{
var
errors
=
_a
.
errors
,
fields
=
_a
.
fields
;
resolve
({
errors
:
errors
,
fields
:
fields
});
});
});
};
//# sourceMappingURL=validate.js.map
\ No newline at end of file
server/duibats/dist/decorator/validate.js.map
View file @
1f54aff7
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/decorator/validate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAGa,QAAA,cAAc,GAAG,UAAC,SAAiB;IAC9C,OAAO,UAAU,MAAc,EAAE,IAAY,EAAE,UAA8B;QAC3E,IAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAA;QAE/B,UAAU,CAAC,KAAK,GAAG;YAAU,cAAc;iBAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;gBAAd,yBAAc;;YAClC,IAAA,OAAO,GAAoB,IAAI,GAAxB,EAAE,KAAkB,IAAI,GAAR,EAAd,SAAS,mBAAG,EAAE,KAAA,CAAQ;YACtC,IAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;YAExC,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,OAAO,eAAO,SAAS,EAAG,CAAC,CAAA;QAC1D,CAAC,CAAA;IACH,CAAC,CAAA;AACH,CAAC,CAAA"}
\ No newline at end of file
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/decorator/validate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,cAAc;AACd,8BAAqC;AACrC,0CAAyC;AACzC,mDAA+C;AAElC,QAAA,cAAc,GAAG,UAAC,UAAiB;IAC9C,OAAO,UAAU,MAAc,EAAE,IAAY,EAAE,UAA8B;QAC3E,IAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAA;QAE/B,UAAU,CAAC,KAAK,GAAG;;YAAgB,cAAc;iBAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;gBAAd,yBAAc;;;;;;;4BACxC,OAAO,GAAoB,IAAI,GAAxB,EAAE,KAAkB,IAAI,GAAR,EAAd,SAAS,mBAAG,EAAE,KAAA,CAAQ;4BAEnB,qBAAM,cAAc,CAAC,UAAU,EAAE,OAAO,CAAC,IAAI,CAAC,EAAA;;4BAAzD,MAAM,GAAK,CAAA,SAA8C,CAAA,OAAnD;4BAEd,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;4BACnB,IAAI,MAAM;gCAAE,sBAAO,kBAAY,CAAC,KAAK,CAAC,sBAAU,CAAC,YAAY,QAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAG,CAAC,2CAAG,OAAO,CAAC,EAAA;4BAEpF,sBAAO,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,OAAO,eAAO,SAAS,EAAG,CAAC,EAAA;;;;SACzD,CAAA;IACH,CAAC,CAAA;AACH,CAAC,CAAA;AAED,IAAM,cAAc,GAAG,UAAC,UAAiB,EAAE,IAAY;IACrD,IAAM,SAAS,GAAG,IAAI,yBAAM,CAAC,UAAU,CAAC,CAAA;IAExC,OAAO,IAAI,OAAO,CAAC,UAAA,OAAO;QACxB,SAAS;aACN,QAAQ,CAAC,IAAI,CAAC;aACd,IAAI,CAAC;YACJ,OAAO,CAAC,EAAE,CAAC,CAAA;QACb,CAAC,CAAC;aACD,KAAK,CAAC,UAAC,EAAkB;gBAAhB,MAAM,YAAA,EAAE,MAAM,YAAA;YACtB,OAAO,CAAC,EAAE,MAAM,QAAA,EAAE,MAAM,QAAA,EAAE,CAAC,CAAA;QAC7B,CAAC,CAAC,CAAA;IACN,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
\ No newline at end of file
server/duibats/dist/index.js
View file @
1f54aff7
...
...
@@ -7,11 +7,13 @@ var seller_controller_1 = require("./controller/seller.controller");
var
awards_controller_1
=
require
(
"./controller/awards.controller"
);
var
rule_controller_1
=
require
(
"./controller/rule.controller"
);
var
taobaoItem_controller_1
=
require
(
"./controller/taobaoItem.controller"
);
var
save_controller_1
=
require
(
"./controller/save.controller"
);
exports
.
default
=
utils_1
.
exportHandlers
([
activity_controller_1
.
default
,
seller_controller_1
.
default
,
awards_controller_1
.
default
,
rule_controller_1
.
default
,
taobaoItem_controller_1
.
default
taobaoItem_controller_1
.
default
,
save_controller_1
.
default
]);
//# sourceMappingURL=index.js.map
\ No newline at end of file
server/duibats/dist/index.js.map
View file @
1f54aff7
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,cAAc;;AAEd,iCAAwC;AACxC,wEAAiE;AACjE,oEAA6D;AAC7D,oEAA6D;AAC7D,gEAAyD;AACzD,4EAAqE;AAErE,kBAAe,sBAAc,CAAC;IAC5B,6BAAkB;IAClB,2BAAgB;IAChB,2BAAgB;IAChB,yBAAc;IACd,+BAAoB;CACrB,CAAC,CAAA"}
\ No newline at end of file
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,cAAc;;AAEd,iCAAwC;AACxC,wEAAiE;AACjE,oEAA6D;AAC7D,oEAA6D;AAC7D,gEAAyD;AACzD,4EAAqE;AACrE,gEAAyD;AAEzD,kBAAe,sBAAc,CAAC;IAC5B,6BAAkB;IAClB,2BAAgB;IAChB,2BAAgB;IAChB,yBAAc;IACd,+BAAoB;IACpB,yBAAc;CACf,CAAC,CAAA"}
\ No newline at end of file
server/duibats/dist/utils/saveValidate.d.ts
View file @
1f54aff7
/** @format */
export
declare
const
activityValidate
:
{
title
:
string
;
};
import
{
Rules
}
from
'async-validator'
;
export
declare
const
saveParams
:
Rules
;
server/duibats/dist/utils/saveValidate.js
View file @
1f54aff7
"use strict"
;
/** @format */
var
__assign
=
(
this
&&
this
.
__assign
)
||
function
()
{
__assign
=
Object
.
assign
||
function
(
t
)
{
for
(
var
s
,
i
=
1
,
n
=
arguments
.
length
;
i
<
n
;
i
++
)
{
s
=
arguments
[
i
];
for
(
var
p
in
s
)
if
(
Object
.
prototype
.
hasOwnProperty
.
call
(
s
,
p
))
t
[
p
]
=
s
[
p
];
}
return
t
;
};
return
__assign
.
apply
(
this
,
arguments
);
};
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
exports
.
activityValidate
=
void
0
;
exports
.
activityValidate
=
{
title
:
''
exports
.
saveParams
=
void
0
;
exports
.
saveParams
=
{
title
:
{
required
:
true
,
type
:
'string'
,
validator
:
function
(
rule
,
value
,
cb
,
source
)
{
value
=
value
.
trim
();
if
(
!
value
)
return
new
Error
(
'活动名称为空'
);
if
(
value
.
length
>
12
)
return
new
Error
(
'活动名称不可超过12个字'
);
return
cb
();
}
},
rule
:
{
required
:
true
,
message
:
'活动规则不可为空'
},
startTime
:
{
required
:
true
,
validator
:
function
(
rule
,
value
,
cb
,
source
)
{
var
endTime
=
source
.
endTime
,
activityId
=
source
.
activityId
;
if
(
!
value
)
return
new
Error
(
'请配置活动开始时间'
);
if
(
value
>
endTime
)
return
new
Error
(
'开始时间不得大于结束时间'
);
if
(
!
activityId
&&
value
<
Date
.
now
())
return
new
Error
(
'新建活动开始时间需小于当前时间'
);
return
cb
();
}
},
endTime
:
{
required
:
true
,
validator
:
function
(
rule
,
value
,
cb
,
source
)
{
if
(
!
value
)
return
new
Error
(
'请配置活动结束时间'
);
}
},
tasks
:
{
required
:
true
,
validator
:
function
(
rule
,
tasks
,
cb
,
source
)
{
var
taskList
=
Object
.
keys
(
tasks
).
map
(
function
(
type
)
{
return
__assign
(
__assign
({},
tasks
[
type
]),
{
type
:
type
});
});
if
(
taskList
.
length
===
0
)
return
new
Error
(
'任务配置必须配置一项'
);
var
canPassTask
=
{
status
:
true
,
message
:
''
};
}
}
};
//# sourceMappingURL=saveValidate.js.map
\ No newline at end of file
server/duibats/dist/utils/saveValidate.js.map
View file @
1f54aff7
{"version":3,"file":"saveValidate.js","sourceRoot":"","sources":["../../src/utils/saveValidate.ts"],"names":[],"mappings":";AAAA,cAAc;;;AAED,QAAA,gBAAgB,GAAG;IAC9B,KAAK,EAAE,EAAE;CACV,CAAA"}
\ No newline at end of file
{"version":3,"file":"saveValidate.js","sourceRoot":"","sources":["../../src/utils/saveValidate.ts"],"names":[],"mappings":";AAAA,cAAc;;;;;;;;;;;;;;AAID,QAAA,UAAU,GAAU;IAC/B,KAAK,EAAE;QACL,QAAQ,EAAE,IAAI;QACd,IAAI,EAAE,QAAQ;QACd,SAAS,YAAC,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM;YAC/B,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAA;YACpB,IAAI,CAAC,KAAK;gBAAE,OAAO,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAA;YACtC,IAAI,KAAK,CAAC,MAAM,GAAG,EAAE;gBAAE,OAAO,IAAI,KAAK,CAAC,cAAc,CAAC,CAAA;YACvD,OAAO,EAAE,EAAE,CAAA;QACb,CAAC;KACF;IACD,IAAI,EAAE;QACJ,QAAQ,EAAE,IAAI;QACd,OAAO,EAAE,UAAU;KACpB;IACD,SAAS,EAAE;QACT,QAAQ,EAAE,IAAI;QACd,SAAS,YAAC,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM;YACvB,IAAA,OAAO,GAAiB,MAAM,QAAvB,EAAE,UAAU,GAAK,MAAM,WAAX,CAAW;YACtC,IAAI,CAAC,KAAK;gBAAE,OAAO,IAAI,KAAK,CAAC,WAAW,CAAC,CAAA;YACzC,IAAI,KAAK,GAAG,OAAO;gBAAE,OAAO,IAAI,KAAK,CAAC,cAAc,CAAC,CAAA;YACrD,IAAI,CAAC,UAAU,IAAI,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE;gBAAE,OAAO,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAA;YAC1E,OAAO,EAAE,EAAE,CAAA;QACb,CAAC;KACF;IACD,OAAO,EAAE;QACP,QAAQ,EAAE,IAAI;QACd,SAAS,YAAC,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM;YAC/B,IAAI,CAAC,KAAK;gBAAE,OAAO,IAAI,KAAK,CAAC,WAAW,CAAC,CAAA;QAC3C,CAAC;KACF;IACD,KAAK,EAAE;QACL,QAAQ,EAAE,IAAI;QACd,SAAS,YAAC,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM;YAC/B,IAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,UAAA,IAAI;gBAC1C,6BAAY,KAAK,CAAC,IAAI,CAAC,KAAE,IAAI,MAAA,IAAE;YACjC,CAAC,CAAC,CAAA;YACF,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO,IAAI,KAAK,CAAC,YAAY,CAAC,CAAA;YACzD,IAAI,WAAW,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,CAAA;QACjD,CAAC;KACF;CACF,CAAA"}
\ No newline at end of file
server/duibats/mockServer/server.js
View file @
1f54aff7
...
...
@@ -26,9 +26,9 @@ app.post('/handler', async (req, res) => {
if
(
!
db
)
{
res
.
json
({
message
:
`参数错误,缺少数据库db`
})
}
//
if (!openId) {
//
res.json({ message: `参数错误,缺少openId` })
//
}
if
(
!
openId
)
{
res
.
json
({
message
:
`参数错误,缺少openId`
})
}
try
{
let
query
=
JSON
.
parse
(
JSON
.
stringify
(
data
))
}
catch
(
e
)
{
...
...
@@ -45,7 +45,6 @@ app.post('/handler', async (req, res) => {
process
.
db
=
db
}
req
.
context
=
{
openId
:
'AAHbOf3jAJ9vbna7X6pnrL'
,
appOwnerOpenId
:
'dsass'
,
db
,
env
:
'mock'
,
...
...
server/duibats/src/controller/save.controller.ts
View file @
1f54aff7
...
...
@@ -4,8 +4,7 @@ import { CODE_TYPES } from './../constants'
import
{
services
,
paramsCheck
,
paramsValidate
}
from
'../decorator'
import
{
resultsModel
}
from
'../sdk'
import
{
ActivityconfigService
}
from
'../service'
import
{
RuleItem
}
from
'async-validator'
import
{
saveParams
}
from
'../utils/saveValidate'
interface
ISaveActivityContext
extends
Context
{
data
:
{
activityId
?:
string
...
...
@@ -17,20 +16,12 @@ interface ISaveActivityContext extends Context {
}
}
// const activityValidate: <T><RuleItem> = {
// title: {
// require: true,
// type: 'string',
// validator: (rule, value, callback, data) => {}
// }
// }
export
default
class
ActivitSaveController
{
/**
* 保存活动
*/
@
paramsCheck
([
'title'
,
'startTime'
,
'endTime'
,
'tasks'
,
'rule'
])
// @paramsValidate(activityValidate
)
//
@paramsCheck(['title', 'startTime', 'endTime', 'tasks', 'rule'])
@
paramsValidate
(
saveParams
)
@
services
([
ActivityconfigService
])
async
saveActivityInfo
(
context
:
ISaveActivityContext
,
{},
[
activityconfigService
]:
[
ActivityconfigService
])
{
const
{
title
=
''
,
activityId
=
''
,
startTime
,
endTime
,
tasks
=
{},
rule
}
=
context
.
data
...
...
server/duibats/src/decorator/validate.ts
View file @
1f54aff7
/** @format */
import
{
resultsModel
}
from
'../sdk'
import
{
CODE_TYPES
}
from
'../constants'
export
const
paramsValidate
=
(
validator
:
object
)
=>
{
import
Schema
,
{
Rules
}
from
'async-validator'
export
const
paramsValidate
=
(
validators
:
Rules
)
=>
{
return
function
(
target
:
Object
,
name
:
string
,
descriptor
:
PropertyDescriptor
)
{
const
method
=
descriptor
.
value
descriptor
.
value
=
function
(...
args
:
any
[])
{
descriptor
.
value
=
async
function
(...
args
:
any
[])
{
const
[
context
,
otherArgs
=
{}]
=
args
const
params
=
Object
.
keys
(
context
.
data
)
// @ts-ignore
const
{
errors
}
=
await
validateParams
(
validators
,
context
.
data
)
console
.
log
(
errors
)
if
(
errors
)
return
resultsModel
.
error
(
CODE_TYPES
.
SYSTEM_ERROR
,
errors
?.[
0
]?.
message
)
return
method
.
apply
(
target
,
[
context
,
{
...
otherArgs
}])
}
}
}
const
validateParams
=
(
validators
:
Rules
,
data
:
object
)
=>
{
const
validator
=
new
Schema
(
validators
)
return
new
Promise
(
resolve
=>
{
validator
.
validate
(
data
)
.
then
(()
=>
{
resolve
({})
})
.
catch
(({
errors
,
fields
})
=>
{
resolve
({
errors
,
fields
})
})
})
}
server/duibats/src/index.ts
View file @
1f54aff7
...
...
@@ -6,11 +6,13 @@ import SellerController from './controller/seller.controller'
import
AwardsController
from
'./controller/awards.controller'
import
RuleController
from
'./controller/rule.controller'
import
RaobaoItemController
from
'./controller/taobaoItem.controller'
import
SaveController
from
'./controller/save.controller'
export
default
exportHandlers
([
ActivityController
,
SellerController
,
AwardsController
,
RuleController
,
RaobaoItemController
RaobaoItemController
,
SaveController
])
server/duibats/src/utils/saveValidate.ts
0 → 100644
View file @
1f54aff7
/** @format */
import
{
Rules
}
from
'async-validator'
export
const
saveParams
:
Rules
=
{
title
:
{
required
:
true
,
type
:
'string'
,
validator
(
rule
,
value
,
cb
,
source
)
{
value
=
value
.
trim
()
if
(
!
value
)
return
new
Error
(
'活动名称为空'
)
if
(
value
.
length
>
12
)
return
new
Error
(
'活动名称不可超过12个字'
)
return
cb
()
}
},
rule
:
{
required
:
true
,
message
:
'活动规则不可为空'
},
startTime
:
{
required
:
true
,
validator
(
rule
,
value
,
cb
,
source
)
{
const
{
endTime
,
activityId
}
=
source
if
(
!
value
)
return
new
Error
(
'请配置活动开始时间'
)
if
(
value
>
endTime
)
return
new
Error
(
'开始时间不得大于结束时间'
)
if
(
!
activityId
&&
value
<
Date
.
now
())
return
new
Error
(
'新建活动开始时间需小于当前时间'
)
return
cb
()
}
},
endTime
:
{
required
:
true
,
validator
(
rule
,
value
,
cb
,
source
)
{
if
(
!
value
)
return
new
Error
(
'请配置活动结束时间'
)
}
},
tasks
:
{
required
:
true
,
validator
(
rule
,
tasks
,
cb
,
source
)
{
const
taskList
=
Object
.
keys
(
tasks
).
map
(
type
=>
{
return
{
...
tasks
[
type
],
type
}
})
if
(
taskList
.
length
===
0
)
return
new
Error
(
'任务配置必须配置一项'
)
let
canPassTask
=
{
status
:
true
,
message
:
''
}
}
}
}
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