diff --git a/src/migrations/1731186421123-addarchivetorequests.ts b/src/migrations/1731186421123-addarchivetorequests.ts new file mode 100644 index 0000000..72c8e60 --- /dev/null +++ b/src/migrations/1731186421123-addarchivetorequests.ts @@ -0,0 +1,13 @@ +import {MigrationInterface, QueryRunner} from "typeorm"; + +export class AddArchiveToRequest1731186421123 implements MigrationInterface { + name = 'AddArchiveToRequest1731186421123' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "Request" ADD COLUMN IF NOT EXISTS "archive" boolean NOT NULL DEFAULT false`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "Request" DROP COLUMN IF EXISTS "archive"`); + } +} \ No newline at end of file diff --git a/src/models/RequestModel.ts b/src/models/RequestModel.ts index e8a45ae..6b696bd 100644 --- a/src/models/RequestModel.ts +++ b/src/models/RequestModel.ts @@ -31,6 +31,7 @@ export class RequestModel { id: this.id, title: this.title, description: this.description, + archive: this.archive, user: this.user, matches: this.matches, }; diff --git a/src/repositories/PostRepository.ts b/src/repositories/PostRepository.ts index 1605fae..f974993 100644 --- a/src/repositories/PostRepository.ts +++ b/src/repositories/PostRepository.ts @@ -128,7 +128,7 @@ export class PostRepository extends AbstractRepository { .createQueryBuilder() .update(PostModel) .set({ archive: true }) - .where("userId = :userId", { userId }) + .where("user.id = :userId", { userId }) .execute(); } diff --git a/src/repositories/RequestRepository.ts b/src/repositories/RequestRepository.ts index bb5fa19..1f7e400 100644 --- a/src/repositories/RequestRepository.ts +++ b/src/repositories/RequestRepository.ts @@ -31,11 +31,13 @@ export class RequestRepository extends AbstractRepository { public async createRequest( title: string, description: string, + archive: boolean, user: UserModel ): Promise { const request = this.repository.create({ title, description, + archive, user, }); await this.repository.save(request); @@ -56,7 +58,7 @@ export class RequestRepository extends AbstractRepository { .createQueryBuilder() .update(RequestModel) .set({ archive: true }) - .where("userId = :userId", { userId }) + .where("user.id = :userId", { userId }) .execute(); } diff --git a/src/services/RequestService.ts b/src/services/RequestService.ts index 9fd9048..1a17bc6 100644 --- a/src/services/RequestService.ts +++ b/src/services/RequestService.ts @@ -49,7 +49,7 @@ export class RequestService { const user = await userRepository.getUserById(request.userId); if (!user) throw new NotFoundError('User not found!'); const requestRepository = Repositories.request(transactionalEntityManager); - return await requestRepository.createRequest(request.title, request.description, user); + return await requestRepository.createRequest(request.title, request.description, request.archive, user); }); } diff --git a/src/tests/RequestTest.test.ts b/src/tests/RequestTest.test.ts index dc00f34..4339522 100644 --- a/src/tests/RequestTest.test.ts +++ b/src/tests/RequestTest.test.ts @@ -29,6 +29,7 @@ beforeEach(async () => { expectedRequest.id = '81e6896c-a549-41bf-8851-604e7fbd4f1f'; expectedRequest.title = 'Textbook'; expectedRequest.description = 'Textbook for CS 1110'; + expectedRequest.archive = false; }); afterAll(async () => { @@ -105,6 +106,7 @@ describe('request tests', () => { const newRequest = { title: 'Textbook', description: 'Textbook for CS 1110', + archive: false, userId: user.id, }; diff --git a/src/tests/data/RequestFactory.ts b/src/tests/data/RequestFactory.ts index 26c620c..c5c224e 100644 --- a/src/tests/data/RequestFactory.ts +++ b/src/tests/data/RequestFactory.ts @@ -26,6 +26,7 @@ export class RequestFactory { fakeRequest.id = '81e6896c-a549-41bf-8851-604e7fbd4f1f'; fakeRequest.title = 'Textbook'; fakeRequest.description = 'Textbook for CS 1110'; + fakeRequest.archive = false; return fakeRequest; } diff --git a/src/types/ApiRequests.ts b/src/types/ApiRequests.ts index e2cbd46..eee054f 100644 --- a/src/types/ApiRequests.ts +++ b/src/types/ApiRequests.ts @@ -109,6 +109,7 @@ export interface UploadImageRequest { export interface CreateRequestRequest { title: string; description: string; + archive: boolean; userId: Uuid; } diff --git a/src/types/ApiResponses.ts b/src/types/ApiResponses.ts index e24644a..73f55bd 100644 --- a/src/types/ApiResponses.ts +++ b/src/types/ApiResponses.ts @@ -139,6 +139,7 @@ export interface Request { id: Uuid; title: string; description: string; + archive: boolean; user: PrivateProfile; matches: PostModel[]; }