1
0
Fork 0

fix: getNamespace error

Signed-off-by: MiaoWoo <admin@yumc.pw>
master
MiaoWoo 2019-10-17 15:56:15 +08:00
parent 9380fd6ec6
commit 1f60ee9353
5 changed files with 12 additions and 12 deletions

View File

@ -6,6 +6,8 @@
"author": "MiaoWoo <admin@yumc.pw>", "author": "MiaoWoo <admin@yumc.pw>",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"clean": "npx lerna run clean",
"watch": "npx lerna run watch --parallel",
"build": "npx lerna run build", "build": "npx lerna run build",
"lp": "npx lerna publish" "lp": "npx lerna publish"
}, },

View File

@ -1,3 +1,5 @@
import { httpGet as get, httpPost as post } from 'inversify-express-utils'
export * from './decorators' export * from './decorators'
export * from './activation' export * from './activation'
export * from 'inversify-express-utils' export * from 'inversify-express-utils'
export { get, post }

View File

@ -1,12 +1,8 @@
import { TYPE, io } from '@cc-server/ws'
import { DBClient } from '@cc-server/db' import { DBClient } from '@cc-server/db'
import { inject, postConstruct } from '@cc-server/ioc'; import { inject, postConstruct } from '@cc-server/ioc';
import { Vaild, NotBlank, NotNull, controller, requestBody, httpGet, httpPost, requestParam } from '@cc-server/binding' import { Vaild, NotBlank, NotNull, controller, requestBody, get, post, requestParam } from '@cc-server/binding'
import '@cc-server/db-mongo' import '@cc-server/db-mongo'
//process.env.FAAS_MONGO_URL = 'mongodb://192.168.0.2:27017';
//process.env.FAAS_MONGO_DB = "faas";
const TABLE = 'users' const TABLE = 'users'
class ExampleModel { class ExampleModel {
@ -29,30 +25,29 @@ export class Controller {
this.client.setTable(TABLE); this.client.setTable(TABLE);
} }
@httpGet('/') @get('/')
public async list(): Promise<ExampleModel[]> { public async list(): Promise<ExampleModel[]> {
return this.client.find({}); return this.client.find({});
} }
@httpGet('/:id') @get('/:id')
public async get( public async get(
@requestParam('id') id: string @requestParam('id') id: string
): Promise<ExampleModel> { ): Promise<ExampleModel> {
return this.client.findOneById(id); return this.client.findOneById(id);
} }
@httpPost('/') @post('/')
public async create( public async create(
@Vaild() @requestBody() model: ExampleModel @Vaild() @requestBody() model: ExampleModel
): Promise<ExampleModel> { ): Promise<ExampleModel> {
return model; return model;
//return this.client.insertOne(model);
} }
@httpPost('/:id') @post('/:id')
public async update( public async update(
@requestParam('id') id: string, @requestParam('id') id: string,
@requestBody() model: ExampleModel @Vaild() @requestBody() model: ExampleModel
): Promise<boolean> { ): Promise<boolean> {
return this.client.updateById(id, model); return this.client.updateById(id, model);
} }

View File

@ -1,2 +1,2 @@
export * from 'mongodb' export * from 'mongodb'
export * from './client' export * from './client'

View File

@ -4,6 +4,7 @@ import { getContainer } from '@cc-server/ioc'
import { getNamespaceMetadata, getNamespaceListenerMetadata } from './utils' import { getNamespaceMetadata, getNamespaceListenerMetadata } from './utils'
export function getNamespaceInfo() { export function getNamespaceInfo() {
if (!getContainer().isBound(TYPE.Namespace)) { return [] };
let namespaces = getContainer().getAll<interfaces.Namespace>(TYPE.Namespace) let namespaces = getContainer().getAll<interfaces.Namespace>(TYPE.Namespace)
return namespaces.map(namespace => { return namespaces.map(namespace => {
let namespaceMetadata = getNamespaceMetadata(namespace); let namespaceMetadata = getNamespaceMetadata(namespace);