Skip to content

Commit 5727508

Browse files
authored
Merge pull request #16 from import-ai/feature/collect
Feature/collect
2 parents 8e088b6 + f976730 commit 5727508

23 files changed

+421
-155
lines changed

.env.example

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
PORT=9005
1+
PORT=3000
2+
23
DB_HOST=host.docker.internal
34
DB_PORT=5432
45
DB_DATABASE=omnibox
56
DB_USERNAME=omnibox
67
DB_PASSWORD=omnibox
78
DB_LOGGING=true
89
DB_SYNC=true
10+
911
JWT_SECRET=your-secret-key
1012
JWT_EXPIRE=72000s
13+
1114
# REDIS_URL=redis://redis:6379
1215
# REDIS_PORT=6379
1316
# REDIS_TTL=3600

compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ services:
22
app:
33
build: .
44
ports:
5-
- '8000:9005'
5+
- "8000:${PORT}"
66
env_file:
77
- .env
88
depends_on:

pnpm-lock.yaml

Lines changed: 72 additions & 53 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/auth/auth.controller.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ export class AuthController {
1515
}
1616

1717
@Public()
18-
@Post('register')
19-
async register(@Body('url') url: string, @Body('email') email: string) {
20-
return await this.authService.register(url, email);
18+
@Post('sign-up')
19+
async signUp(@Body('url') url: string, @Body('email') email: string) {
20+
return await this.authService.signUp(url, email);
2121
}
2222

2323
@Public()
24-
@Post('register-confirm')
25-
async registerComFirm(
24+
@Post('sign-up/confirm')
25+
async signUpConfirm(
2626
@Body('token') token: string,
2727
@Body('username') username: string,
2828
@Body('password') password: string,
2929
@Body('password_repeat') password_repeat: string,
3030
) {
31-
return await this.authService.registerConfirm(token, {
31+
return await this.authService.signUpConfirm(token, {
3232
username,
3333
password,
3434
password_repeat,
@@ -45,7 +45,7 @@ export class AuthController {
4545
}
4646

4747
@Public()
48-
@Post('password-confirm')
48+
@Post('password/confirm')
4949
async resetPassword(
5050
@Body('token') token: string,
5151
@Body('password') password: string,
@@ -71,8 +71,8 @@ export class AuthController {
7171
});
7272
}
7373

74-
@Post('invite-confirm')
75-
async inviteComFirm(@Body('token') token: string) {
74+
@Post('invite/confirm')
75+
async inviteConfirm(@Body('token') token: string) {
7676
return await this.authService.inviteConfirm(token);
7777
}
7878
}

src/auth/auth.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import { JwtAuthGuard } from 'src/auth/jwt-auth.guard';
1010
import { LocalStrategy } from 'src/auth/local.strategy';
1111
import { AuthController } from 'src/auth/auth.controller';
1212
import { ConfigService, ConfigModule } from '@nestjs/config';
13+
import { InternalAuthController } from 'src/auth/internal.auth.controller';
1314
import { NamespacesModule } from 'src/namespaces/namespaces.module';
1415

1516
@Module({
1617
exports: [AuthService],
17-
controllers: [AuthController],
18+
controllers: [AuthController, InternalAuthController],
1819
providers: [
1920
AuthService,
2021
JwtStrategy,

src/auth/auth.service.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { JwtService } from '@nestjs/jwt';
22
import { MailService } from 'src/mail/mail.service';
33
import { UserService } from 'src/user/user.service';
44
import { NamespacesService } from 'src/namespaces/namespaces.service';
5+
import { CreateUserDto } from 'src/user/dto/create-user.dto';
56
import {
67
Injectable,
78
ForbiddenException,
@@ -48,7 +49,23 @@ export class AuthService {
4849
};
4950
}
5051

51-
async register(url: string, email: string) {
52+
async signUpWithoutConfirm(createUser: CreateUserDto) {
53+
const account = await this.userService.findByEmail(createUser.email);
54+
if (account) {
55+
throw new BadRequestException('Email already registered');
56+
}
57+
const user = await this.userService.create(createUser);
58+
return {
59+
id: user.id,
60+
username: user.username,
61+
access_token: this.jwtService.sign({
62+
sub: user.id,
63+
email: user.email,
64+
}),
65+
};
66+
}
67+
68+
async signUp(url: string, email: string) {
5269
const account = await this.userService.findByEmail(email);
5370
if (account) {
5471
throw new BadRequestException(
@@ -61,10 +78,10 @@ export class AuthService {
6178
expiresIn: '1h',
6279
},
6380
);
64-
await this.mailService.sendRegisterEmail(email, `${url}?token=${token}`);
81+
await this.mailService.sendSignUpEmail(email, `${url}?token=${token}`);
6582
}
6683

67-
async registerConfirm(
84+
async signUpConfirm(
6885
token: string,
6986
data: {
7087
username: string;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { AuthService } from 'src/auth/auth.service';
2+
import { Public } from 'src/auth/decorators/public.decorator';
3+
import { Controller, Body, Post } from '@nestjs/common';
4+
import { CreateUserDto } from 'src/user/dto/create-user.dto';
5+
6+
@Controller('internal/api/v1')
7+
export class InternalAuthController {
8+
constructor(private authService: AuthService) {}
9+
10+
@Public()
11+
@Post('sign-up')
12+
async signUp(@Body() createUserDto: CreateUserDto) {
13+
return await this.authService.signUpWithoutConfirm(createUserDto);
14+
}
15+
}

src/mail/mail.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import { MailerService } from '@nestjs-modules/mailer';
55
export class MailService {
66
constructor(private readonly mailerService: MailerService) {}
77

8-
async sendRegisterEmail(email: string, resetUrl: string): Promise<void> {
8+
async sendSignUpEmail(email: string, resetUrl: string): Promise<void> {
99
try {
1010
await this.mailerService.sendMail({
1111
to: email,
1212
subject: 'Continue completing account registration',
13-
template: './register',
13+
template: './sign-up',
1414
context: {
1515
resetUrl,
1616
},
File renamed without changes.

src/namespaces/namespaces.entity.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@ export class Namespace extends Base {
1414

1515
@Column('uuid', { array: true, default: [] })
1616
owner_id: string[];
17+
18+
@Column({ type: 'int', default: 1 })
19+
max_running_tasks: number;
1720
}

0 commit comments

Comments
 (0)