0.1.6 • Published 3 years ago

wuuhuu v0.1.6

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

wuuhuu

app start

// app.ts
import express = require('express')
import { FearlessServer } from './lib/FearlessServer'

async function start() {
  let app = express()
  let fServer = FearlessServer.create(app)
  app.use((req, res, next) => {
    res.status(404).json({ code: 404, msg: `Not found2: ${req.method} ${req.path}` })
  })
  fServer.listen(3000, () => {
    console.log(`app start at 3000 port`)
  })
}

start()

controller

// DemoController.ts
import { Controller, ControllerContent } from '../../lib/Controller'
import { Inject } from '../../lib/Inject'
import { Get } from '../../lib/Method'
import { DefaultContentStrategy } from '../../lib/midwares/Content'
import { Query } from '../../lib/Param'
import { Numeral, Pick, Required } from '../../lib/validation/ParamValidate'
import { Validate } from '../../lib/validation/Validate'
import { DemoService } from '../service/DemoService'

@Controller('/demo')
@ControllerContent(DefaultContentStrategy)
export class DemoController {
  @Inject()
  demoService: DemoService

  @Get('/save')
  @Validate
  async save(@Query() @Numeral('err message', 1) id: number) {
    return this.demoService.say()
  }

  @Get('/photo')
  @Validate
  async photo(@Query() @Numeral('id field') id: number) {
    return await this.demoService.findOnePhoto(id)
  }

  @Get('/content')
  async getContnet() {
    return this.demoService.getContent()
  }
}

service

// DemoService.ts
import { Inject, InjectRepo } from '../../lib/Inject'
import { DefaultContentData } from '../../lib/midwares/Content'
import { Provider } from '../../lib/Provider'
import { ServiceBase } from '../../lib/ServiceBase'
import { PhotoRepo } from '../repo/PhotoRepo'
import { Demo2Service } from './Demo2Service'

@Provider()
export class DemoService extends ServiceBase<DefaultContentData> {
  @Inject()
  demo2: Demo2Service
  @InjectRepo()
  photoRepo: PhotoRepo

  say() {
    return this.demo2.say2()
  }

  async findOnePhoto(id: number) {
    console.log(this.content)
    return await this.photoRepo.findOne(id)
  }

  getContent() {
    return this.demo2.outputContent()
  }
}
0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago