Commit 9f2a025a authored by maggie's avatar maggie

save

parent 0e1d8117
{
"controllers": {
"common": {
"awards": {
"getMyPrizeList": {
"decorators": [
{
"type": "common",
"name": "checkParams",
"params": [
"activityId"
]
},
{
"type": "common",
"name": "registeInfos",
"params": [
"activityInfo"
]
}
]
},
"receiveObjectPrize": {
"decorators": [
{
"type": "common",
"name": "checkParams",
"params": [
"activityId",
"id",
"name",
"phone",
"province",
"city",
"addressDetail",
"streetName"
]
},
{
"type": "common",
"name": "registeInfos",
"params": [
"activityInfo"
]
},
{
"type": "common",
"name": "preCheck",
"params": [
{
"type": "common",
"behave": "check",
"name": "checkAwardReceiveExpired"
},
{
"type": "common",
"behave": "check",
"name": "checkReceivePrize",
"params": {
"prizeType": 5
}
}
]
}
]
}
}
}
}
}
\ No newline at end of file
/** @format */
const fs = require('fs-extra')
const CodeGenerateConfig = require('./config')
const Model = CodeGenerateConfig.model
const run = async (gulp, nunjucksRender, rename, nunjucksRenderConfig) => {
nunjucksRenderConfig.data = {
model: {},
config: 111
}
}
export default {
run
}
// module.exports = {
// run: async function(gulp, nunjucksRender, rename, nunjucksRenderConfig) {
// nunjucksRenderConfig.data = {
// model: CodeGenerateConfig.model,
// config: CodeGenerateConfig.config
// }
// const ServerProjectRootPath = nunjucksRenderConfig.ServerFullPath
// //server
// const serverTemplatePath = 'templates/taobao_mini'
// const customService = {}
// for(let controller in Model) {
// const fnServices = {}
// for(let fn in Model[controller]) {
// fnServices[fn] = {}
// for(let decorator of Model[controller][fn].decorator) {
// if(decorator.type === 'custom') {
// await gulp.src(`${serverTemplatePath}/decorator/decorator.njk`)
// .pipe(nunjucksRender({
// ...nunjucksRenderConfig,
// data: {
// model: decorator,
// }
// }))
// .pipe(rename(`${decorator.name}.ts`))
// .pipe(
// gulp.dest(
// ServerProjectRootPath +
// CodeGenerateConfig.config.CustomDecoratorRelativePath
// )
// )
// }
// }
// for(let main of Model[controller][fn].main) {
// if(main.type === 'custom') {
// if(!customService[main.service]) {
// customService[main.service] = {}
// }
// if(!customService[main.service][main.function]) {
// customService[main.service][main.function] = main
// }
// }
// fnServices[fn][`${main.type}_${main.service}`] = main
// }
// }
// // 编译common/controller
// await gulp.src(`${serverTemplatePath}/controller/${controller}.controller.njk`)
// .pipe(nunjucksRender({
// ...nunjucksRenderConfig,
// data: {
// model: CodeGenerateConfig.model[controller],
// config: CodeGenerateConfig.config,
// services: fnServices
// }
// }))
// .pipe(rename(`${controller}.controller.ts`))
// .pipe(
// gulp.dest(
// ServerProjectRootPath +
// CodeGenerateConfig.config.ControllerRelativePath + 'common/'
// )
// )
// }
// // 编译custom/service
// for(let service in customService) {
// await gulp.src(`${serverTemplatePath}/service/service.njk`)
// .pipe(nunjucksRender({
// ...nunjucksRenderConfig,
// data: {
// model: {
// name: service,
// functions: customService[service]
// },
// }
// }))
// .pipe(rename(`${service}.service.ts`))
// .pipe(
// gulp.dest(
// ServerProjectRootPath +
// CodeGenerateConfig.config.CustomServiceRelativePath
// )
// )
// }
// await gulp.src(`${serverTemplatePath}/service/index.njk`)
// .pipe(nunjucksRender({
// ...nunjucksRenderConfig,
// data: {
// model: {
// customService
// }
// }
// }))
// .pipe(rename(`index.ts`))
// .pipe(
// gulp.dest(
// ServerProjectRootPath +
// CodeGenerateConfig.config.CustomServiceRelativePath
// )
// )
// }
// }
\ No newline at end of file
/** @format */
const gulp = require('gulp')
const rename = require('gulp-rename')
const nunjucksRender = require('gulp-nunjucks-render')
const codeGenerate = require('./templates/generate')
var jsScript = 'node'
if (process.env.npm_config_argv !== undefined && process.env.npm_config_argv.indexOf('debug') > 0) {
jsScript = 'node debug'
}
const ServerFullPath = require('./package.json').ServerFullPath
//const FrontendFullPath = require('./package.json').FrontendFullPath;
const nunjucksRenderConfig = {
path: 'templates/server',
envOptions: {
tags: {
blockStart: '<%',
blockEnd: '%>',
variableStart: '<$',
variableEnd: '$>',
commentStart: '<#',
commentEnd: '#>'
}
},
ext: '.ts',
ServerFullPath
}
gulp.task('code', function () {
require('events').EventEmitter.defaultMaxListeners = 0
return codeGenerate.run(gulp, nunjucksRender, rename, nunjucksRenderConfig)
})
{
"name": "nunjucks-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"ServerFullPath": "lazy-mock",
"devDependencies": {
"gulp": "^4.0.2",
"gulp-nunjucks-render": "^2.2.3",
"gulp-rename": "^2.0.0"
},
"dependencies": {
"fs-extra": "^9.0.1"
}
}
/** @format */
export const <$ decoratorName $> = (target: any, name: string, descriptor: PropertyDescriptor) => {
const method = descriptor.value
descriptor.value = async function (...args: any[]) {
const [context, otherArgs = {}] = args
return method.apply(this, [context, { ...otherArgs }])
}
}
\ No newline at end of file
/**
* @format
*/
export default class <$ serviceName $> {
context: IContext<any>
constructor(context: IContext<any>) {
this.context = context
}
/**
* @desc 活动基本信息
* @param {活动id} activityId
* @returns 返回活动详情,若不存在活动,返回为null
*/
async getBaseInfo(activityId: string): Promise<IActivityInfo> {
return await this.activitydao.findOne({ _id: activityId, deleteStatus: ACTIVITY_STATUS.NORMAL })
}
/**
*
* 根据itemIds获取商品列表
*
* @param {string} itemIds
* @param {string} session
* @return {Array}
* @memberof BaseService
*/
async getItemListByIds(itemIds: string, session: string): Promise<Array<ITaoBaoItems>> {
const GOODSINFO =
'detail_url,approve_status,num_iid,title,nick,type,cid,pic_url,num,props,valid_thru,list_time,desc,price,has_discount,has_invoice,has_warranty,has_showcase,modified,delist_time,postage_id,seller_cids,outer_id,sold_quantity'
const result = await TBAPIS.getItemListByItemIds(this.context, session, itemIds, { fields: GOODSINFO })
const items = result?.items?.item || []
const list = items.map(
(v: { num_iid: string; title: string; price: string; detail_url: string; pic_url: string; desc: string }) => {
return {
itemId: v.num_iid,
name: v.title,
price: v.price,
url: v.detail_url,
image: v.pic_url,
desc: v.desc
}
}
)
return list
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment