Browse Source

feat: create nest js project

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5444/head
Pranav C 2 years ago
parent
commit
ac13742d91
  1. 25
      packages/nocodb-nest/.eslintrc.js
  2. 35
      packages/nocodb-nest/.gitignore
  3. 4
      packages/nocodb-nest/.prettierrc
  4. 73
      packages/nocodb-nest/README.md
  5. 8
      packages/nocodb-nest/nest-cli.json
  6. 17204
      packages/nocodb-nest/package-lock.json
  7. 80
      packages/nocodb-nest/package.json
  8. 13
      packages/nocodb-nest/src/app.module.ts
  9. 20
      packages/nocodb-nest/src/auth/auth.controller.spec.ts
  10. 31
      packages/nocodb-nest/src/auth/auth.controller.ts
  11. 19
      packages/nocodb-nest/src/auth/auth.module.ts
  12. 18
      packages/nocodb-nest/src/auth/auth.service.spec.ts
  13. 207
      packages/nocodb-nest/src/auth/auth.service.ts
  14. 4
      packages/nocodb-nest/src/auth/constants.ts
  15. 18
      packages/nocodb-nest/src/connection/connection.spec.ts
  16. 24
      packages/nocodb-nest/src/connection/connection.ts
  17. 0
      packages/nocodb-nest/src/init.ts
  18. 18
      packages/nocodb-nest/src/local.strategy/local.strategy.spec.ts
  19. 19
      packages/nocodb-nest/src/local.strategy/local.strategy.ts
  20. 8
      packages/nocodb-nest/src/main.ts
  21. 18
      packages/nocodb-nest/src/meta/meta.service.spec.ts
  22. 74
      packages/nocodb-nest/src/meta/meta.service.ts
  23. 14
      packages/nocodb-nest/src/noco.ts
  24. 7
      packages/nocodb-nest/src/users/user.spec.ts
  25. 1
      packages/nocodb-nest/src/users/user.ts
  26. 20
      packages/nocodb-nest/src/users/users.controller.spec.ts
  27. 7
      packages/nocodb-nest/src/users/users.controller.ts
  28. 9
      packages/nocodb-nest/src/users/users.module.ts
  29. 18
      packages/nocodb-nest/src/users/users.service.spec.ts
  30. 17
      packages/nocodb-nest/src/users/users.service.ts
  31. 24
      packages/nocodb-nest/test/app.e2e-spec.ts
  32. 9
      packages/nocodb-nest/test/jest-e2e.json
  33. 4
      packages/nocodb-nest/tsconfig.build.json
  34. 21
      packages/nocodb-nest/tsconfig.json

25
packages/nocodb-nest/.eslintrc.js

@ -0,0 +1,25 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};

35
packages/nocodb-nest/.gitignore vendored

@ -0,0 +1,35 @@
# compiled output
/dist
/node_modules
# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# OS
.DS_Store
# Tests
/coverage
/.nyc_output
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

4
packages/nocodb-nest/.prettierrc

@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}

73
packages/nocodb-nest/README.md

@ -0,0 +1,73 @@
<p align="center">
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a>
</p>
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
[circleci-url]: https://circleci.com/gh/nestjs/nest
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
<p align="center">
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
</p>
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->
## Description
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
## Installation
```bash
$ npm install
```
## Running the app
```bash
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
```
## Test
```bash
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov
```
## Support
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
## Stay in touch
- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com)
- Website - [https://nestjs.com](https://nestjs.com/)
- Twitter - [@nestframework](https://twitter.com/nestframework)
## License
Nest is [MIT licensed](LICENSE).

8
packages/nocodb-nest/nest-cli.json

@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true
}
}

17204
packages/nocodb-nest/package-lock.json generated

File diff suppressed because it is too large Load Diff

80
packages/nocodb-nest/package.json

@ -0,0 +1,80 @@
{
"name": "nest-sample-proj",
"version": "0.0.1",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"scripts": {
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@nestjs/common": "^9.0.0",
"@nestjs/core": "^9.0.0",
"@nestjs/jwt": "^10.0.3",
"@nestjs/mapped-types": "*",
"@nestjs/platform-express": "^9.0.0",
"bcryptjs": "^2.4.3",
"knex": "^2.4.2",
"nocodb-sdk": "file:../nocodb-sdk",
"passport-jwt": "^4.0.1",
"pg": "^8.10.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.2.0",
"sqlite3": "^5.1.6",
"uuid": "^9.0.0"
},
"devDependencies": {
"@nestjs/cli": "^9.0.0",
"@nestjs/schematics": "^9.0.0",
"@nestjs/testing": "^9.0.0",
"@nestjsplus/dyn-schematics": "^1.0.12",
"@types/express": "^4.17.13",
"@types/jest": "29.5.0",
"@types/node": "18.15.11",
"@types/passport-jwt": "^3.0.8",
"@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "29.5.0",
"prettier": "^2.3.2",
"source-map-support": "^0.5.20",
"supertest": "^6.1.3",
"ts-jest": "29.0.5",
"ts-loader": "^9.2.3",
"ts-node": "^10.0.0",
"tsconfig-paths": "4.2.0",
"typescript": "^4.7.4"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}

13
packages/nocodb-nest/src/app.module.ts

@ -0,0 +1,13 @@
import { Module } from '@nestjs/common';
import { Connection } from './connection/connection';
import { AuthModule } from './auth/auth.module';
import { UsersModule } from './users/users.module';
import { MetaService } from './meta/meta.service';
import { LocalStrategy } from './local.strategy/local.strategy';
@Module({
imports: [AuthModule, UsersModule],
controllers: [],
providers: [Connection, MetaService, LocalStrategy],
})
export class AppModule {}

20
packages/nocodb-nest/src/auth/auth.controller.spec.ts

@ -0,0 +1,20 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AuthController } from './auth.controller';
import { AuthService } from './auth.service';
describe('AuthController', () => {
let controller: AuthController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [AuthController],
providers: [AuthService],
}).compile();
controller = module.get<AuthController>(AuthController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});

31
packages/nocodb-nest/src/auth/auth.controller.ts

@ -0,0 +1,31 @@
import { AuthService } from './auth.service';
import { Controller, Request, Post, UseGuards, Body } from "@nestjs/common";
import { AuthGuard } from '@nestjs/passport';
export class CreateUserDto {
readonly username: string;
readonly email: string;
readonly password: string;
}
@Controller('auth')
export class AuthController {
constructor(private readonly authService: AuthService) {}
@UseGuards(AuthGuard('local'))
@Post('signin')
async signin(@Request() req) {
return this.authService.login(req.user);
}
@Post('signup')
async signup(@Body() createUserDto: CreateUserDto) {
const user = await this.authService.signup(createUserDto);
}
}

19
packages/nocodb-nest/src/auth/auth.module.ts

@ -0,0 +1,19 @@
import { Module } from '@nestjs/common';
import { AuthService } from './auth.service';
import { AuthController } from './auth.controller';
import { UsersModule } from "../users/users.module";
import { JwtModule } from "@nestjs/jwt";
import { jwtConstants } from "./constants";
@Module({
controllers: [AuthController],
providers: [AuthService],
imports:[
UsersModule,
JwtModule.register({
secret: jwtConstants.secret,
signOptions: { expiresIn: '60s' },
}),
]
})
export class AuthModule {}

18
packages/nocodb-nest/src/auth/auth.service.spec.ts

@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AuthService } from './auth.service';
describe('AuthService', () => {
let service: AuthService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [AuthService],
}).compile();
service = module.get<AuthService>(AuthService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});

207
packages/nocodb-nest/src/auth/auth.service.ts

@ -0,0 +1,207 @@
import { Injectable } from '@nestjs/common';
import { UsersService } from '../users/users.service';
import { promisify } from 'util';
import bcrypt from 'bcryptjs';
import { JwtService } from '@nestjs/jwt';
import { CreateUserDto } from './auth.controller';
import { v4 as uuidv4 } from 'uuid';
import { Connection } from '../connection/connection';
@Injectable()
export class AuthService {
constructor(
private usersService: UsersService,
private jwtService: JwtService,
private connection: Connection,
) {}
async validateUser(email: string, pass: string): Promise<any> {
const user = await this.usersService.findOne(email);
if (user) {
const { password, ...result } = user;
const hashedPassword = await promisify(bcrypt.hash)(password, user.salt);
if (user.password !== hashedPassword) {
return user;
}
}
return null;
}
async login(user: any) {
const payload = { username: user.username, sub: user.userId };
return {
access_token: this.jwtService.sign(payload),
};
}
async signup(createUserDto: CreateUserDto) {
const {
email: _email,
firstname,
lastname,
token,
ignore_subscribe,
} = createUserDto as any;
let { password } = createUserDto;
// // validate password and throw error if password is satisfying the conditions
// const { valid, error } = validatePassword(password);
// if (!valid) {
// NcError.badRequest(`Password : ${error}`);
// }
//
// if (!isEmail(_email)) {
// NcError.badRequest(`Invalid email`);
// }
const email = _email.toLowerCase();
let user = await this.usersService.findOne(email);
if (user) {
// if (token) {
// if (token !== user.invite_token) {
// NcError.badRequest(`Invalid invite url`);
// } else if (user.invite_token_expires < new Date()) {
// NcError.badRequest(
// 'Expired invite url, Please contact super admin to get a new invite url'
// );
// }
// } else {
// // todo : opening up signup for timebeing
// // return next(new Error(`Email '${email}' already registered`));
// }
}
const salt = await promisify(bcrypt.genSalt)(10);
password = await promisify(bcrypt.hash)(password, salt);
const email_verification_token = uuidv4();
//
// if (!ignore_subscribe) {
// T.emit('evt_subscribe', email);
// }
if (user) {
// if (token) {
// await User.update(user.id, {
// firstname,
// lastname,
// salt,
// password,
// email_verification_token,
// invite_token: null,
// invite_token_expires: null,
// email: user.email,
// });
// } else {
// NcError.badRequest('User already exist');
// }
} else {
await registerNewUserIfAllowed({
firstname,
lastname,
email,
salt,
password,
email_verification_token,
});
}
user = await this.usersService.findOne(email);
//
// try {
// const template = (await import('./ui/emailTemplates/verify')).default;
// await (
// await NcPluginMgrv2.emailAdapter()
// ).mailSend({
// to: email,
// subject: 'Verify email',
// html: ejs.render(template, {
// verifyLink:
// (param.req as any).ncSiteUrl +
// `/email/verify/${user.email_verification_token}`,
// }),
// });
// } catch (e) {
// console.log(
// 'Warning : `mailSend` failed, Please configure emailClient configuration.'
// );
// }
// await promisify((param.req as any).login.bind(param.req))(user);
// const refreshToken = ''//randomTokenString();
//
// await User.update(user.id, {
// refresh_token: refreshToken,
// email: user.email,
// });
//
// setTokenCookie(param.res, refreshToken);
//
// user = (param.req as any).user;
// await Audit.insert({
// op_type: 'AUTHENTICATION',
// op_sub_type: 'SIGNUP',
// user: user.email,
// description: `signed up `,
// ip: (param.req as any).clientIp,
// });
return this.login(user);
}
async registerNewUserIfAllowed({
firstname,
lastname,
email,
salt,
password,
email_verification_token,
}: {
firstname;
lastname;
email: string;
salt: any;
password;
email_verification_token;
}) {
let roles: string = OrgUserRoles.CREATOR;
// if (await User.isFirst()) {
// roles = `${OrgUserRoles.CREATOR},${OrgUserRoles.SUPER_ADMIN}`;
// // todo: update in nc_store
// // roles = 'owner,creator,editor'
// T.emit('evt', {
// evt_type: 'project:invite',
// count: 1,
// });
// } else {
// let settings: { invite_only_signup?: boolean } = {};
// try {
// settings = JSON.parse((await Store.get(NC_APP_SETTINGS))?.value);
// } catch {}
//
// if (settings?.invite_only_signup) {
// NcError.badRequest('Not allowed to signup, contact super admin.');
// } else {
// roles = OrgUserRoles.VIEWER;
// }
// }
const token_version = randomTokenString();
return await this.co.insert({
firstname,
lastname,
email,
salt,
password,
email_verification_token,
roles,
token_version,
});
}
}

4
packages/nocodb-nest/src/auth/constants.ts

@ -0,0 +1,4 @@
export const jwtConstants = {
// read from .env file
secret: 'some_random_key',
};

18
packages/nocodb-nest/src/connection/connection.spec.ts

@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { Connection } from './knex';
describe('Knex', () => {
let provider: Connection;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [Connection],
}).compile();
provider = module.get<Connection>(Connection);
});
it('should be defined', () => {
expect(provider).toBeDefined();
});
});

24
packages/nocodb-nest/src/connection/connection.ts

@ -0,0 +1,24 @@
import { Injectable } from "@nestjs/common";
import * as knex from "knex";
@Injectable()
export class Connection {
private readonly knex: knex.Knex;
constructor() {
this.knex = knex.default({
client: "mysql2",
connection: {
host: "localhost",
user: "root",
password: "password",
database: "my_database"
}
});
}
get knexInstance(): knex.Knex {
return this.knex;
}
}

0
packages/nocodb-nest/src/init.ts

18
packages/nocodb-nest/src/local.strategy/local.strategy.spec.ts

@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { LocalStrategy } from './local.strategy';
describe('LocalStrategy', () => {
let provider: LocalStrategy;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [LocalStrategy],
}).compile();
provider = module.get<LocalStrategy>(LocalStrategy);
});
it('should be defined', () => {
expect(provider).toBeDefined();
});
});

19
packages/nocodb-nest/src/local.strategy/local.strategy.ts

@ -0,0 +1,19 @@
import { Strategy } from 'passport-local';
import { PassportStrategy } from '@nestjs/passport';
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { AuthService } from '../auth/auth.service';
@Injectable()
export class LocalStrategy extends PassportStrategy(Strategy) {
constructor(private authService: AuthService) {
super();
}
async validate(username: string, password: string): Promise<any> {
const user = await this.authService.validateUser(username, password);
if (!user) {
throw new UnauthorizedException();
}
return user;
}
}

8
packages/nocodb-nest/src/main.ts

@ -0,0 +1,8 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(8080);
}
bootstrap();

18
packages/nocodb-nest/src/meta/meta.service.spec.ts

@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { MetaService } from './meta.service';
describe('MetaService', () => {
let service: MetaService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [MetaService],
}).compile();
service = module.get<MetaService>(MetaService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});

74
packages/nocodb-nest/src/meta/meta.service.ts

@ -0,0 +1,74 @@
import { Injectable } from '@nestjs/common';
import { Connection } from '../connection/connection';
@Injectable()
export class MetaService {
constructor(private connection: Connection) {
}
public async metaGet(
project_id: string,
dbAlias: string,
target: string,
idOrCondition: string | { [p: string]: any },
fields?: string[],
// xcCondition?
): Promise<any> {
const query = this.connection.knexInstance(target);
// if (xcCondition) {
// query.condition(xcCondition);
// }
if (fields?.length) {
query.select(...fields);
}
if (project_id !== null && project_id !== undefined) {
query.where('project_id', project_id);
}
if (dbAlias !== null && dbAlias !== undefined) {
query.where('db_alias', dbAlias);
}
if (!idOrCondition) {
return query.first();
}
if (typeof idOrCondition !== 'object') {
query.where('id', idOrCondition);
} else {
query.where(idOrCondition);
}
// console.log(query.toQuery())
return query.first();
}
public async metaInsert2(
project_id: string,
base_id: string,
target: string,
data: any,
ignoreIdGeneration?: boolean
): Promise<any> {
const id = data?.id || this.genNanoid(target);
const insertObj = {
...data,
...(ignoreIdGeneration ? {} : { id }),
created_at: data?.created_at || this.knexConnection?.fn?.now(),
updated_at: data?.updated_at || this.knexConnection?.fn?.now(),
};
if (base_id !== null) insertObj.base_id = base_id;
if (project_id !== null) insertObj.project_id = project_id;
// validate insert object before insert
await this.validateObject(target, insertObj);
await this.knexConnection(target).insert(insertObj);
return insertObj;
}
}

14
packages/nocodb-nest/src/noco.ts

@ -0,0 +1,14 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import * as express from 'express';
export default async function(app = express()) {
const nestApp = await NestFactory.create(AppModule);
await nestApp.init();
app.use(nestApp.getHttpAdapter().getInstance());
return app;
}

7
packages/nocodb-nest/src/users/user.spec.ts

@ -0,0 +1,7 @@
import { User } from './user';
describe('User', () => {
it('should be defined', () => {
expect(new User()).toBeDefined();
});
});

1
packages/nocodb-nest/src/users/user.ts

@ -0,0 +1 @@
export class User {}

20
packages/nocodb-nest/src/users/users.controller.spec.ts

@ -0,0 +1,20 @@
import { Test, TestingModule } from '@nestjs/testing';
import { UsersController } from './users.controller';
import { UsersService } from './users.service';
describe('UsersController', () => {
let controller: UsersController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [UsersController],
providers: [UsersService],
}).compile();
controller = module.get<UsersController>(UsersController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});

7
packages/nocodb-nest/src/users/users.controller.ts

@ -0,0 +1,7 @@
import { Controller } from '@nestjs/common';
import { UsersService } from './users.service';
@Controller('users')
export class UsersController {
constructor(private readonly usersService: UsersService) {}
}

9
packages/nocodb-nest/src/users/users.module.ts

@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { UsersService } from './users.service';
import { UsersController } from './users.controller';
@Module({
controllers: [UsersController],
providers: [UsersService]
})
export class UsersModule {}

18
packages/nocodb-nest/src/users/users.service.spec.ts

@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { UsersService } from './users.service';
describe('UsersService', () => {
let service: UsersService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [UsersService],
}).compile();
service = module.get<UsersService>(UsersService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});

17
packages/nocodb-nest/src/users/users.service.ts

@ -0,0 +1,17 @@
import { Injectable } from '@nestjs/common';
import { MetaService } from '../meta/meta.service';
@Injectable()
export class UsersService {
constructor(private metaService: MetaService) {
}
async findOne(email: string) {
const user = await this.metaService.metaGet(null, null, 'users', { email });
return user;
}
}

24
packages/nocodb-nest/test/app.e2e-spec.ts

@ -0,0 +1,24 @@
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import * as request from 'supertest';
import { AppModule } from './../src/app.module';
describe('AppController (e2e)', () => {
let app: INestApplication;
beforeEach(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
}).compile();
app = moduleFixture.createNestApplication();
await app.init();
});
it('/ (GET)', () => {
return request(app.getHttpServer())
.get('/')
.expect(200)
.expect('Hello World!');
});
});

9
packages/nocodb-nest/test/jest-e2e.json

@ -0,0 +1,9 @@
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": ".",
"testEnvironment": "node",
"testRegex": ".e2e-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
}
}

4
packages/nocodb-nest/tsconfig.build.json

@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
}

21
packages/nocodb-nest/tsconfig.json

@ -0,0 +1,21 @@
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false
}
}
Loading…
Cancel
Save