Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 139 additions & 4 deletions nodejs/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,140 @@
node_modules
dist
# Logs
logs
*.log
*.md
.git
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# vitepress build output
**/.vitepress/dist

# vitepress cache directory
**/.vitepress/cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

.git
.vscode
.DS_Store
20 changes: 11 additions & 9 deletions nodejs/docker-compose.yml → nodejs/compose.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
version: '3.8'

services:
app:
build: .
container_name: app
ports:
- '3000:9005'
env_file:
- .env
depends_on:
- db
# - redis
db:
condition: service_healthy

db:
image: postgres
container_name: postgres
image: postgres:17-alpine
ports:
- "5432:5432"
environment:
Expand All @@ -21,11 +19,15 @@ services:
- POSTGRES_PASSWORD=${DB_PASSWORD}
volumes:
- postgres_data:/var/lib/postgresql/data
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
# - ./init.sql:/docker-entrypoint-initdb.d/init.sql
healthcheck:
test: [ "CMD", "pg_isready", "-q", "-d", "omnibox", "-U", "omnibox" ]
interval: 30s
timeout: 10s
retries: 5

pgadmin:
image: dpage/pgadmin4
container_name: pgadmin4
ports:
- "8888:80"
environment:
Expand Down
5 changes: 5 additions & 0 deletions nodejs/pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
onlyBuiltDependencies:
- '@nestjs/core'
- '@scarf/scarf'
- '@swc/core'
- bcrypt
6 changes: 6 additions & 0 deletions nodejs/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
import { AuthModule } from 'src/auth/auth.module';
import { UserModule } from 'src/user/user.module';
import { AppController } from './app.controller';
import { NamespacesModule } from 'src/namespaces/namespaces.module';
import { ResourcesModule } from 'src/resources/resources.module';
import { TasksModule } from 'src/tasks/tasks.module';

@Module({
controllers: [AppController],
imports: [
AuthModule,
UserModule,
NamespacesModule,
ResourcesModule,
TasksModule,
ConfigModule.forRoot({
cache: true,
isGlobal: true,
Expand Down
23 changes: 23 additions & 0 deletions nodejs/src/namespaces/namespaces.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Controller, Get, Post, Delete, Body, Param, Query } from '@nestjs/common';
import { NamespacesService } from './namespaces.service';
import { Namespace } from './namespaces.entity';

@Controller('api/namespaces')
export class NamespacesController {
constructor(private readonly namespacesService: NamespacesService) {}

@Get()
async getNamespaces(@Query('userId') userId: string): Promise<Namespace[]> {
return this.namespacesService.getNamespaces(userId);
}

@Post()
async createNamespace(@Body('name') name: string, @Body('ownerId') ownerId: string): Promise<Namespace> {
return this.namespacesService.createNamespace(name, ownerId);
}

@Delete('/:namespaceId')
async deleteNamespace(@Param('namespaceId') namespaceId: string, @Query('userId') userId: string): Promise<void> {
return this.namespacesService.deleteNamespace(namespaceId, userId);
}
}
32 changes: 32 additions & 0 deletions nodejs/src/namespaces/namespaces.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
DeleteDateColumn,
} from 'typeorm';

@Entity('namespaces')
export class Namespace {
@PrimaryGeneratedColumn('uuid')
namespaceId: string;

@Column({ unique: true, nullable: false })
name: string;

@Column({ nullable: false })
ownerId: string;

@Column({ type: 'simple-array', nullable: true })
collaborators: string[];

@CreateDateColumn()
createdAt: Date;

@UpdateDateColumn()
updatedAt: Date;

@DeleteDateColumn({ nullable: true })
deletedAt: Date;
}
13 changes: 13 additions & 0 deletions nodejs/src/namespaces/namespaces.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { NamespacesService } from './namespaces.service';
import { NamespacesController } from './namespaces.controller';
import { Namespace } from './namespaces.entity';
import { Resource } from 'src/resources/resources.entity';

@Module({
imports: [TypeOrmModule.forFeature([Namespace, Resource])],
providers: [NamespacesService],
controllers: [NamespacesController],
})
export class NamespacesModule {}
64 changes: 64 additions & 0 deletions nodejs/src/namespaces/namespaces.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Injectable, NotFoundException, ForbiddenException } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository, IsNull } from 'typeorm';
import { Namespace } from './namespaces.entity';
import { Resource } from 'src/resources/resources.entity';

@Injectable()
export class NamespacesService {
constructor(
@InjectRepository(Namespace)
private namespaceRepository: Repository<Namespace>,
@InjectRepository(Resource)
private resourceRepository: Repository<Resource>,
) {}

async getNamespaces(userId: string): Promise<Namespace[]> {
return this.namespaceRepository.find({
where: [
{ ownerId: userId, deletedAt: IsNull() },
{ collaborators: userId, deletedAt: IsNull() },
],
});
}

async createNamespace(name: string, ownerId: string): Promise<Namespace> {
const newNamespace = this.namespaceRepository.create({ name, ownerId });
const savedNamespace = await this.namespaceRepository.save(newNamespace);

const rootParams = {
namespaceId: savedNamespace.namespaceId,
resourceType: 'folder',
};

const teamspaceRoot = this.resourceRepository.create({
...rootParams,
spaceType: 'teamspace',
});

const privateRoot = this.resourceRepository.create({
...rootParams,
spaceType: 'private',
});

await this.resourceRepository.save([teamspaceRoot, privateRoot]);
return savedNamespace;
}

async deleteNamespace(namespaceId: string, userId: string): Promise<void> {
const namespace = await this.namespaceRepository.findOne({
where: { namespaceId, deletedAt: IsNull() },
});

if (!namespace) {
throw new NotFoundException('Namespace not found');
}

if (namespace.ownerId !== userId) {
throw new ForbiddenException('You do not have permission to delete this namespace');
}

namespace.deletedAt = new Date();
await this.namespaceRepository.save(namespace);
}
}
34 changes: 34 additions & 0 deletions nodejs/src/resources/resources.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Controller, Post, Get, Patch, Delete, Body, Query, Param } from '@nestjs/common';
import { ResourcesService } from './resources.service';
import { Resource } from './resources.entity';
import { User } from 'src/user/user.entity';

@Controller('api/resources')
export class ResourcesController {
constructor(private readonly resourcesService: ResourcesService) {}

@Post()
async createResource(@Body() data: Partial<Resource>, @Body('user') user: User) {
return this.resourcesService.createResource(data, user);
}

@Get('/root')
async getRootResource(@Query('namespaceId') namespaceId: string, @Query('spaceType') spaceType: string, @Query('userId') userId: string) {
return this.resourcesService.getRootResource(namespaceId, spaceType, userId);
}

@Get()
async getResources(@Query() query: any) {
return this.resourcesService.getResources(query);
}

@Patch('/:resourceId')
async updateResource(@Param('resourceId') resourceId: string, @Body() data: Partial<Resource>) {
return this.resourcesService.updateResource(resourceId, data);
}

@Delete('/:resourceId')
async deleteResource(@Param('resourceId') resourceId: string) {
return this.resourcesService.deleteResource(resourceId);
}
}
Loading