| 40 | sandboxMode, |
| 41 | } from 'src/chat/sandbox-provider'; |
| 42 | |
| 43 | @Injectable() |
| 44 | export class ProjectService { |
| 45 | private readonly logger = new Logger('ProjectService'); |
| 46 | |
| 47 | constructor( |
| 48 | @InjectRepository(Project) |
| 49 | private projectsRepository: Repository<Project>, |
| 50 | @InjectRepository(Chat) |
| 51 | private chatRepository: Repository<Chat>, |
| 52 | private chatService: ChatService, |
| 53 | private uploadService: UploadService, |
| 54 | // private readonly gitHubService: GitHubService, |
| 55 | private userService: UserService, |
| 56 | private previews: PreviewService, |
| 57 | private workspaces: WorkspaceService, |
| 58 | ) {} |
| 59 | |
| 60 | async getProjectsByUser(userId: string): Promise<Project[]> { |
| 61 | const projects = await this.projectsRepository.find({ |
| 62 | where: { userId, isDeleted: false }, |
| 63 | relations: ['chats'], |
| 64 | }); |
| 65 | |
| 66 | if (projects && projects.length > 0) { |
| 67 | await Promise.all( |
| 68 | projects.map(async (project) => { |
| 69 | // Filter deleted chats |
| 70 | if (project.chats) { |
| 71 | const chats = await project.chats; |
| 72 | this.logger.log('Project chats:', chats); |
| 73 | // Create a new Promise that resolves to filtered chats |
| 74 | project.chats = Promise.resolve( |
| 75 | chats.filter((chat) => !chat.isDeleted), |
| 76 | ); |
| 77 | } |
| 78 | }), |
| 79 | ); |
| 80 | } |
| 81 | |
| 82 | return projects.length > 0 ? projects : []; |
| 83 | } |
| 84 | |
| 85 | async getProjectById(projectId: string): Promise<Project> { |
| 86 | const project = await this.projectsRepository.findOne({ |
| 87 | where: { id: projectId, isDeleted: false }, |
| 88 | relations: ['chats', 'user'], |
| 89 | }); |
| 90 | |
| 91 | if (!project) { |
| 92 | throw new NotFoundException(`Project with ID ${projectId} not found.`); |
| 93 | } |
| 94 | |
| 95 | if (project.chats) { |
| 96 | const chats = await project.chats; |
| 97 | this.logger.log('Project chats:', chats); |
| 98 | project.chats = Promise.resolve(chats.filter((chat) => !chat.isDeleted)); |
| 99 | } |
nothing calls this directly
no test coverage detected