feat: implement authentication and database modules with relations and group management

Added new authentication strategies (JWT and GitHub OAuth), guards, and controllers. Implemented database module, schema with relations, and group management features, including CRD operations and person-to-group associations. Integrated validation and CORS configuration.
This commit is contained in:
2025-05-15 17:09:36 +02:00
parent f6f0888bd7
commit 9f99b80784
63 changed files with 2838 additions and 0 deletions

View File

@@ -0,0 +1,108 @@
import { Injectable, NotFoundException, Inject } from '@nestjs/common';
import { eq, and } from 'drizzle-orm';
import { DRIZZLE } from '../../../database/database.module';
import * as schema from '../../../database/schema';
import { CreateProjectDto } from '../dto/create-project.dto';
import { UpdateProjectDto } from '../dto/update-project.dto';
@Injectable()
export class ProjectsService {
constructor(@Inject(DRIZZLE) private readonly db: any) {}
/**
* Create a new project
*/
async create(createProjectDto: CreateProjectDto) {
const [project] = await this.db
.insert(schema.projects)
.values(createProjectDto)
.returning();
return project;
}
/**
* Find all projects
*/
async findAll() {
return this.db.select().from(schema.projects);
}
/**
* Find projects by owner ID
*/
async findByOwnerId(ownerId: string) {
return this.db
.select()
.from(schema.projects)
.where(eq(schema.projects.ownerId, ownerId));
}
/**
* Find a project by ID
*/
async findById(id: string) {
const [project] = await this.db
.select()
.from(schema.projects)
.where(eq(schema.projects.id, id));
if (!project) {
throw new NotFoundException(`Project with ID ${id} not found`);
}
return project;
}
/**
* Update a project
*/
async update(id: string, updateProjectDto: UpdateProjectDto) {
const [project] = await this.db
.update(schema.projects)
.set({
...updateProjectDto,
updatedAt: new Date(),
})
.where(eq(schema.projects.id, id))
.returning();
if (!project) {
throw new NotFoundException(`Project with ID ${id} not found`);
}
return project;
}
/**
* Delete a project
*/
async remove(id: string) {
const [project] = await this.db
.delete(schema.projects)
.where(eq(schema.projects.id, id))
.returning();
if (!project) {
throw new NotFoundException(`Project with ID ${id} not found`);
}
return project;
}
/**
* Check if a user has access to a project
*/
async checkUserAccess(projectId: string, userId: string) {
const [project] = await this.db
.select()
.from(schema.projects)
.where(
and(
eq(schema.projects.id, projectId),
eq(schema.projects.ownerId, userId)
)
);
return !!project;
}
}