diff --git a/src/modules/configuration/couch/couch.module.ts b/src/modules/configuration/couch/couch.module.ts new file mode 100644 index 0000000..f178f74 --- /dev/null +++ b/src/modules/configuration/couch/couch.module.ts @@ -0,0 +1,17 @@ +import { ConfigModule } from "@nestjs/config"; +import { CouchDataController } from "./infrastructure/couch.controller"; +import { Module } from "@nestjs/common"; + +@Module({ + imports: [ + ConfigModule.forRoot(), + // TypeOrmModule.forFeature([UserPrivilegeModel], CONNECTION_NAME.DEFAULT), + // CqrsModule, + ], + controllers: [ + CouchDataController + ], + providers: [ + ], + }) + export class CouchModule {} \ No newline at end of file diff --git a/src/modules/configuration/couch/index.ts b/src/modules/configuration/couch/index.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/modules/configuration/couch/infrastructure/couch.controller.ts b/src/modules/configuration/couch/infrastructure/couch.controller.ts new file mode 100644 index 0000000..d5028b7 --- /dev/null +++ b/src/modules/configuration/couch/infrastructure/couch.controller.ts @@ -0,0 +1,66 @@ +import { Body, Controller, Get, Post } from "@nestjs/common"; + +import { ApiTags } from "@nestjs/swagger"; +import { Unprotected } from "src/core/guards"; +import * as Nano from 'nano' +import { CreateUserPrivilegeDto } from "src/modules/user-related/user-privilege/infrastructure/dto/create-user-privilege.dto"; + +@ApiTags(`couch`) +@Controller('couch') +@Unprotected() +export class CouchDataController { + + @Post() + async createDoc( + @Body() entity: CreateUserPrivilegeDto + ) { + try { + let n = Nano('http://admin:secret@127.0.0.1:5984') + let db = await n.db.create(entity.name) + } catch (error) { + console.log(error, 'dsa') + } + } + + @Post('doc') + async createDocs( + @Body() entity: CreateUserPrivilegeDto + ) { + try { + const nano = require("nano")("http://admin:secret@127.0.0.1:5984"); + const people = nano.db.use('string'); + console.log(await people.info()) + const data = { + id: '1212', + name: 'dsadas' + } + // await people.insert(data) + + people.changesReader.start() + .on('change', (change) => { console.log(change) }) + .on('batch', (b) => { + console.log('a batch of', b.length, 'changes has arrived'); + }).on('seq', (s) => { + console.log('sequence token', s); + }).on('error', (e) => { + console.error('error', e); + }) + + } catch (error) { + console.log(error, 'dsa') + } + } + + @Get() + async getDoc( + ) { + try { + let n = Nano('http://admin:secret@127.0.0.1:5984') + const people = n.use('string'); + + // return people.get(); + } catch (error) { + console.log(error, 'dsa') + } + } +} \ No newline at end of file