diff --git a/SerpentRace_Backend/src/Application/DTOs/Mappers/DeckMapper.ts b/SerpentRace_Backend/src/Application/DTOs/Mappers/DeckMapper.ts index d1536a1b..25d276c0 100644 --- a/SerpentRace_Backend/src/Application/DTOs/Mappers/DeckMapper.ts +++ b/SerpentRace_Backend/src/Application/DTOs/Mappers/DeckMapper.ts @@ -1,7 +1,6 @@ import { DeckAggregate } from '../../../Domain/Deck/DeckAggregate'; import { UserAggregate } from '../../../Domain/User/UserAggregate'; import { CreateDeckDto, UpdateDeckDto, ShortDeckDto, DetailDeckDto } from '../DeckDto'; -import e from 'express'; export class DeckMapper { static toShortDto(deck: DeckAggregate, userId?: string): ShortDeckDto { diff --git a/SerpentRace_Backend/src/Application/DTOs/Mappers/OrganizationMapper.ts b/SerpentRace_Backend/src/Application/DTOs/Mappers/OrganizationMapper.ts index 695b17ee..70ff5352 100644 --- a/SerpentRace_Backend/src/Application/DTOs/Mappers/OrganizationMapper.ts +++ b/SerpentRace_Backend/src/Application/DTOs/Mappers/OrganizationMapper.ts @@ -22,7 +22,7 @@ export class OrganizationMapper { contactemail: org.contactemail, state: org.state, regdate: org.regdate, - updatedate: org.updatedate, + updateDate: org.updateDate, url: org.url, userinorg: org.userinorg, maxOrganizationalDecks: org.maxOrganizationalDecks, diff --git a/SerpentRace_Backend/src/Application/DTOs/OrganizationDto.ts b/SerpentRace_Backend/src/Application/DTOs/OrganizationDto.ts index e82c27f6..c1eb4aaf 100644 --- a/SerpentRace_Backend/src/Application/DTOs/OrganizationDto.ts +++ b/SerpentRace_Backend/src/Application/DTOs/OrganizationDto.ts @@ -27,7 +27,7 @@ export interface DetailOrganizationDto { contactemail: string; state: number; regdate: Date; - updatedate: Date; + updateDate: Date; url: string | null; userinorg: number; maxOrganizationalDecks: number | null; diff --git a/SerpentRace_Backend/src/Application/Deck/commands/UpdateDeckCommandHandler.ts b/SerpentRace_Backend/src/Application/Deck/commands/UpdateDeckCommandHandler.ts index 8e5b2ca5..6bfa536a 100644 --- a/SerpentRace_Backend/src/Application/Deck/commands/UpdateDeckCommandHandler.ts +++ b/SerpentRace_Backend/src/Application/Deck/commands/UpdateDeckCommandHandler.ts @@ -9,12 +9,12 @@ export class UpdateDeckCommandHandler { constructor(private readonly deckRepo: IDeckRepository) {} async execute(cmd: UpdateDeckCommand): Promise { - if(cmd.state !== undefined && cmd.userstate!==1) { + if(cmd.state !== undefined && cmd.authLevel!==1) { throw new Error('Only admin users can change deck state'); } try { let existingDeck: DeckAggregate | null = null; - if (cmd.userstate === 1) { + if (cmd.authLevel === 1) { existingDeck = await this.deckRepo.findByIdIncludingDeleted(cmd.id); } else { existingDeck = await this.deckRepo.findById(cmd.id); diff --git a/SerpentRace_Backend/src/Application/User/commands/LogoutCommandHandler.ts b/SerpentRace_Backend/src/Application/User/commands/LogoutCommandHandler.ts index c6648076..ccbda81c 100644 --- a/SerpentRace_Backend/src/Application/User/commands/LogoutCommandHandler.ts +++ b/SerpentRace_Backend/src/Application/User/commands/LogoutCommandHandler.ts @@ -86,7 +86,7 @@ export class LogoutCommandHandler { // 5. Update user's last logout timestamp in database try { - const updateResult = await this.userRepo.update(userId, { updatedate: new Date() }); + const updateResult = await this.userRepo.update(userId, { updateDate: new Date() }); if (updateResult) { logAuth('User last logout timestamp updated', userId); } @@ -151,7 +151,7 @@ export class LogoutCommandHandler { } // Update user logout timestamp - await this.userRepo.update(userId, { updatedate: new Date() }); + await this.userRepo.update(userId, { updateDate: new Date() }); logAuth('User logged out from all devices', userId); return true; diff --git a/SerpentRace_Backend/src/Domain/Deck/DeckAggregate.ts b/SerpentRace_Backend/src/Domain/Deck/DeckAggregate.ts index 601fe7d8..21537dac 100644 --- a/SerpentRace_Backend/src/Domain/Deck/DeckAggregate.ts +++ b/SerpentRace_Backend/src/Domain/Deck/DeckAggregate.ts @@ -74,8 +74,8 @@ export class DeckAggregate { @Column({ type: 'int', default: CType.PUBLIC }) ctype!: CType; - @UpdateDateColumn({ name: 'update_date' }) - updatedate!: Date; + @UpdateDateColumn() + updateDate!: Date; @Column({ type: 'int', default: State.ACTIVE }) state!: State; diff --git a/SerpentRace_Backend/src/Domain/Game/GameAggregate.ts b/SerpentRace_Backend/src/Domain/Game/GameAggregate.ts index 0ad80db4..ece7aae6 100644 --- a/SerpentRace_Backend/src/Domain/Game/GameAggregate.ts +++ b/SerpentRace_Backend/src/Domain/Game/GameAggregate.ts @@ -86,8 +86,8 @@ export class GameAggregate { @Column({ type: 'timestamp', nullable: true, name: 'finishDate' }) enddate!: Date | null; - @UpdateDateColumn({ name: 'updateDate' }) - updatedate!: Date; + @UpdateDateColumn() + updateDate!: Date; } // Board Generation Types diff --git a/SerpentRace_Backend/src/Domain/Organization/OrganizationAggregate.ts b/SerpentRace_Backend/src/Domain/Organization/OrganizationAggregate.ts index b6d63de8..5a3be365 100644 --- a/SerpentRace_Backend/src/Domain/Organization/OrganizationAggregate.ts +++ b/SerpentRace_Backend/src/Domain/Organization/OrganizationAggregate.ts @@ -35,8 +35,8 @@ export class OrganizationAggregate { @CreateDateColumn() regdate!: Date; - @UpdateDateColumn() - updatedate!: Date; + @UpdateDateColumn({ name: 'updateDate' }) + updateDate!: Date; @Column({ type: 'varchar', length: 500, nullable: true }) url!: string | null; diff --git a/SerpentRace_Backend/src/Domain/User/UserAggregate.ts b/SerpentRace_Backend/src/Domain/User/UserAggregate.ts index 60bab19c..86bd8b7d 100644 --- a/SerpentRace_Backend/src/Domain/User/UserAggregate.ts +++ b/SerpentRace_Backend/src/Domain/User/UserAggregate.ts @@ -51,7 +51,7 @@ export class UserAggregate { regdate!: Date; @UpdateDateColumn() - updatedate!: Date; + updateDate!: Date; @Column({ type: 'timestamp', nullable: true }) Orglogindate!: Date | null; diff --git a/SerpentRace_Backend/src/Infrastructure/Repository/DeckRepository.ts b/SerpentRace_Backend/src/Infrastructure/Repository/DeckRepository.ts index 9eb7594e..3c50b183 100644 --- a/SerpentRace_Backend/src/Infrastructure/Repository/DeckRepository.ts +++ b/SerpentRace_Backend/src/Infrastructure/Repository/DeckRepository.ts @@ -29,7 +29,7 @@ export class DeckRepository implements IDeckRepository { // Get paginated results const decks = await this.repo.find({ where: { state: Not(State.SOFT_DELETE) }, - order: { updatedate: 'DESC' }, + order: { updateDate: 'DESC' }, take: limit, skip: offset }); @@ -57,7 +57,7 @@ export class DeckRepository implements IDeckRepository { // Get paginated results const decks = await this.repo.find({ - order: { updatedate: 'DESC' }, + order: { updateDate: 'DESC' }, take: limit, skip: offset }); diff --git a/SerpentRace_Backend/src/Infrastructure/Repository/GameRepository.ts b/SerpentRace_Backend/src/Infrastructure/Repository/GameRepository.ts index 673b1901..b4832ee2 100644 --- a/SerpentRace_Backend/src/Infrastructure/Repository/GameRepository.ts +++ b/SerpentRace_Backend/src/Infrastructure/Repository/GameRepository.ts @@ -39,7 +39,7 @@ export class GameRepository implements IGameRepository { // Get paginated results const games = await this.repo.find({ where: { state: Not(GameState.CANCELLED) }, - order: { updatedate: 'DESC' }, + order: { updateDate: 'DESC' }, take: limit, skip: offset }); @@ -67,7 +67,7 @@ export class GameRepository implements IGameRepository { // Get paginated results (including deleted) const games = await this.repo.find({ - order: { updatedate: 'DESC' }, + order: { updateDate: 'DESC' }, take: limit, skip: offset }); @@ -153,7 +153,7 @@ export class GameRepository implements IGameRepository { queryBuilder.skip(offset); } - const games = await queryBuilder.orderBy('game.updatedate', 'DESC').getMany(); + const games = await queryBuilder.orderBy('game.updateDate', 'DESC').getMany(); const endTime = performance.now(); logDatabase('Game search completed', `executionTime: ${Math.round(endTime - startTime)}ms, query: ${query}, found: ${games.length}, total: ${totalCount}`); @@ -184,7 +184,7 @@ export class GameRepository implements IGameRepository { queryBuilder.skip(offset); } - const games = await queryBuilder.orderBy('game.updatedate', 'DESC').getMany(); + const games = await queryBuilder.orderBy('game.updateDate', 'DESC').getMany(); const endTime = performance.now(); logDatabase('Game search (including deleted) completed', `executionTime: ${Math.round(endTime - startTime)}ms, query: ${query}, found: ${games.length}, total: ${totalCount}`); @@ -251,7 +251,7 @@ export class GameRepository implements IGameRepository { try { const games = await this.repo.find({ where: { state: GameState.ACTIVE }, - order: { updatedate: 'DESC' } + order: { updateDate: 'DESC' } }); const endTime = performance.now(); logDatabase('Active games query completed', `executionTime: ${Math.round(endTime - startTime)}ms, found: ${games.length}`); @@ -270,7 +270,7 @@ export class GameRepository implements IGameRepository { const queryBuilder = this.repo.createQueryBuilder('game') .where('game.state != :cancelledState', { cancelledState: GameState.CANCELLED }) .andWhere('JSON_CONTAINS(game.players, :playerId)', { playerId: `"${playerId}"` }) - .orderBy('game.updatedate', 'DESC'); + .orderBy('game.updateDate', 'DESC'); const games = await queryBuilder.getMany(); const endTime = performance.now(); diff --git a/SerpentRace_Docker/sql_schema_only.sql b/SerpentRace_Docker/sql_schema_only.sql index e36d9e25..4cc18c87 100644 --- a/SerpentRace_Docker/sql_schema_only.sql +++ b/SerpentRace_Docker/sql_schema_only.sql @@ -19,7 +19,7 @@ CREATE TABLE "Users" ( "phone" VARCHAR(20) NULL, "state" INTEGER NOT NULL DEFAULT 0, "regdate" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedate" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updateDate" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, "Orglogindate" TIMESTAMP NULL ); @@ -33,7 +33,7 @@ CREATE TABLE "Organizations" ( "contactemail" VARCHAR(255) NOT NULL, "state" INTEGER NOT NULL DEFAULT 0, "regdate" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedate" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updateDate" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, "url" VARCHAR(500) NULL, "userinorg" INTEGER NOT NULL DEFAULT 0, "maxOrganizationalDecks" INTEGER NULL @@ -49,7 +49,7 @@ CREATE TABLE "Decks" ( "cards" JSONB NOT NULL DEFAULT '[]', "played_number" INTEGER NOT NULL DEFAULT 0, "ctype" INTEGER NOT NULL DEFAULT 0, - "update_date" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updateDate" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, "state" INTEGER NOT NULL DEFAULT 0, "organization_id" UUID NULL ); @@ -174,40 +174,6 @@ CREATE INDEX "IDX_Games_State" ON "Games" ("state"); CREATE INDEX "IDX_Games_CreatedBy" ON "Games" ("createdBy"); CREATE INDEX "IDX_Games_OrganizationId" ON "Games" ("organizationid"); --- Create update trigger for updatedate columns -CREATE OR REPLACE FUNCTION update_updatedate_column() -RETURNS TRIGGER AS $$ -BEGIN - NEW.updatedate = CURRENT_TIMESTAMP; - RETURN NEW; -END; -$$ language 'plpgsql'; - --- Apply update triggers -CREATE TRIGGER update_users_updatedate - BEFORE UPDATE ON "Users" - FOR EACH ROW EXECUTE FUNCTION update_updatedate_column(); - -CREATE TRIGGER update_organizations_updatedate - BEFORE UPDATE ON "Organizations" - FOR EACH ROW EXECUTE FUNCTION update_updatedate_column(); - -CREATE TRIGGER update_decks_updatedate - BEFORE UPDATE ON "Decks" - FOR EACH ROW EXECUTE FUNCTION update_updatedate_column(); - -CREATE TRIGGER update_chats_updatedate - BEFORE UPDATE ON "Chats" - FOR EACH ROW EXECUTE FUNCTION update_updatedate_column(); - -CREATE TRIGGER update_contacts_updatedate - BEFORE UPDATE ON "Contacts" - FOR EACH ROW EXECUTE FUNCTION update_updatedate_column(); - -CREATE TRIGGER update_games_updatedate - BEFORE UPDATE ON "Games" - FOR EACH ROW EXECUTE FUNCTION update_updatedate_column(); - -- Comments for documentation COMMENT ON TABLE "Users" IS 'User accounts with authentication and profile information'; COMMENT ON TABLE "Organizations" IS 'Organizations that can have multiple users and premium features';