Browse Source

feat: project create api (WIP)

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5444/head
Pranav C 2 years ago
parent
commit
ec6cf8defb
  1. 25
      packages/nocodb-nest/src/helpers/populateMeta.ts
  2. 14
      packages/nocodb-nest/src/projects/projects.controller.ts
  3. 9
      packages/nocodb-nest/src/strategies/jwt.strategy.ts
  4. 3
      packages/nocodb-nest/src/utils/utils.service.ts

25
packages/nocodb-nest/src/helpers/populateMeta.ts

@ -1,19 +1,18 @@
import { ModelTypes, UITypes, ViewTypes } from 'nocodb-sdk';
import Column from '../../../models/Column';
import Model from '../../../models/Model';
import NcHelp from '../../../utils/NcHelp';
import View from '../../../models/View';
import NcConnectionMgrv2 from '../../../utils/common/NcConnectionMgrv2';
import Column from '../models/Column';
import Model from '../models/Model';
import NcHelp from '../utils/NcHelp';
import View from '../models/View';
import getTableNameAlias, {
getColumnNameAlias,
} from '../../helpers/getTableName';
import getColumnUiType from '../../helpers/getColumnUiType';
import mapDefaultDisplayValue from '../../helpers/mapDefaultDisplayValue';
import { extractAndGenerateManyToManyRelations } from '../../../services/metaDiff.svc';
import { IGNORE_TABLES } from '../../../utils/common/BaseApiBuilder';
import type LinkToAnotherRecordColumn from '../../../models/LinkToAnotherRecordColumn';
import type Base from '../../../models/Base';
import type Project from '../../../models/Project';
} from '../helpers/getTableName';
import getColumnUiType from '../helpers/getColumnUiType';
import mapDefaultDisplayValue from '../helpers/mapDefaultDisplayValue';
import { extractAndGenerateManyToManyRelations } from '../../services/metaDiff.svc';
import { IGNORE_TABLES } from '../utils/common/BaseApiBuilder';
import type LinkToAnotherRecordColumn from '../../models/LinkToAnotherRecordColumn';
import type Base from '../models/Base';
import type Project from '../models/Project';
export async function populateMeta(base: Base, project: Project): Promise<any> {
const info = {

14
packages/nocodb-nest/src/projects/projects.controller.ts

@ -1,17 +1,20 @@
import { Body, Controller, Delete, Get, Param, Patch, Post, Query } from '@nestjs/common'
import { Body, Controller, Delete, Get, Param, Patch, Post, Query, Request, UseGuards } from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport';
import isDocker from 'is-docker'
import Noco from '../Noco'
import { packageVersion } from '../utils/packageVersion'
import { ProjectsService } from './projects.service';
@UseGuards(AuthGuard('jwt'))
@Controller()
export class ProjectsController {
constructor(private readonly projectsService: ProjectsService) {}
@Get('/api/v1/db/meta/projects/')
list(@Query() queryParams: Record<string, any>){
list(@Query() queryParams: Record<string, any>, @Request() req){
return this.projectsService.list({
user: { id: '1', roles: 'SUPER_ADMIN' },
user: req.user,
query: queryParams
});
}
@ -76,11 +79,10 @@ export class ProjectsController {
@Post(
'/api/v1/db/meta/projects'
)
async projectCreate(@Body() projectBody: Record<string, any>){
async projectCreate(@Body() projectBody: Record<string, any>, @Request() req){
const project = await this.projectsService.projectCreate({
project: projectBody,
// todo: user
// user: req['user'],
user: req['user'],
});
return project;

9
packages/nocodb-nest/src/strategies/jwt.strategy.ts

@ -1,20 +1,19 @@
import { Injectable, UnauthorizedException } from '@nestjs/common'
import { PassportStrategy } from '@nestjs/passport';
import { Strategy, ExtractJwt } from 'passport-jwt';
import { AuthService } from './auth.service';
import { UsersService } from '../users/users.service'
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
constructor(private authService: AuthService) {
constructor(private userService: UsersService) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
secretOrKey: 'your-secret-key',
jwtFromRequest: ExtractJwt.fromHeader('xc-auth'),
});
}
async validate(payload: any) {
const user = await this.authService.validateUser(payload);
const user = await this.userService.findOne(payload?.email);
if (!user) {
throw new UnauthorizedException();
}

3
packages/nocodb-nest/src/utils/utils.service.ts

@ -3,6 +3,7 @@ import axios from 'axios';
import { compareVersions, validate } from 'compare-versions';
import { NC_ATTACHMENT_FIELD_SIZE } from '../constants';
import { NcError } from '../helpers/catchError'
import { User } from '../models'
import NcConfigFactory from './NcConfigFactory';
import { packageVersion } from './packageVersion';
// import { packageVersion } from '../packageVersion';
@ -57,7 +58,7 @@ interface AllMeta {
@Injectable()
export class UtilsService {
async info() {
const projectHasAdmin = false; //!(await User.isFirst());
const projectHasAdmin = !(await User.isFirst());
const result = {
authType: 'jwt',
projectHasAdmin,

Loading…
Cancel
Save