Skip to content

Commit

Permalink
some 4th column myP{age fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan-g committed Nov 4, 2023
1 parent 72abaa9 commit 1c6fb79
Show file tree
Hide file tree
Showing 13 changed files with 370 additions and 1,574 deletions.
2 changes: 2 additions & 0 deletions src/db/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { EthereumAccountEntity } from '../entities/ethereum.account.entity';
import config from '../config';
import { AllUserEntity } from 'src/entities/user.entity';
import { ChildrenPreRegisterEntity } from 'src/entities/childrenPreRegister.entity';
import { ContributionEntity } from 'src/entities/contribution.entity';

export const postgresDataSourceOptions: DataSourceOptions = {
...config().db1,
Expand Down Expand Up @@ -55,6 +56,7 @@ export const postgresDataSourceOptions: DataSourceOptions = {
MidjourneyEntity,
CommentEntity,
ChildrenPreRegisterEntity,
ContributionEntity,
],
};

Expand Down
39 changes: 39 additions & 0 deletions src/features/family/family.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
ForbiddenException,
Get,
Param,
Patch,
Req,
} from '@nestjs/common';
import { FamilyService } from './family.service';
Expand All @@ -29,6 +30,7 @@ import { ServerError } from 'src/filters/server-exception.filter';
import { PaymentService } from '../payment/payment.service';
import { NeedService } from '../need/need.service';
import { isAuthenticated } from 'src/utils/auth';
import { UserService } from '../user/user.service';

@ApiTags('Family')
@ApiSecurity('flask-access-token')
Expand All @@ -41,6 +43,7 @@ import { isAuthenticated } from 'src/utils/auth';
export class FamilyController {
constructor(
private readonly familyService: FamilyService,
private userService: UserService,
private childrenService: ChildrenService,
private needService: NeedService,
private paymentService: PaymentService,
Expand Down Expand Up @@ -496,4 +499,40 @@ export class FamilyController {
},
};
}

@Get(`email/status`)
@ApiOperation({ description: 'Get all contributors' })
async getEmailStatus(@Req() req: Request) {
const dappFlaskUserId = req.headers['dappFlaskUserId'];
if (dappFlaskUserId) {
if (!isAuthenticated(dappFlaskUserId, FlaskUserTypesEnum.FAMILY)) {
throw new ForbiddenException(403, 'You Are not authorized');
}
}
let nestFamilyMember = await this.userService.getFamilyByFlaskId(
dappFlaskUserId,
);
if (!nestFamilyMember) {
nestFamilyMember = await this.userService.createFamily(dappFlaskUserId);
}
return nestFamilyMember.monthlyEmail;
}

@Patch(`email/status`)
@ApiOperation({ description: 'Get all contributors' })
async updateEmailStatus(@Req() req: Request) {
const dappFlaskUserId = req.headers['dappFlaskUserId'];
if (dappFlaskUserId) {
if (!isAuthenticated(dappFlaskUserId, FlaskUserTypesEnum.FAMILY)) {
throw new ForbiddenException(403, 'You Are not authorized');
}
}
let nestFamilyMember = await this.userService.getFamilyByFlaskId(
dappFlaskUserId,
);
if (!nestFamilyMember) {
nestFamilyMember = await this.userService.createFamily(dappFlaskUserId);
}
return await this.familyService.updateEmailMarketing(nestFamilyMember);
}
}
19 changes: 14 additions & 5 deletions src/features/family/family.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ import {
} from 'src/types/interfaces/interface';
import { InjectRepository } from '@nestjs/typeorm';
import { Need } from 'src/entities/flaskEntities/need.entity';
import { And, ArrayContains, IsNull, Not, Repository } from 'typeorm';
import { And, IsNull, Not, Repository, UpdateResult } from 'typeorm';
import { Payment } from 'src/entities/flaskEntities/payment.entity';
import { Child } from 'src/entities/flaskEntities/child.entity';
import { User } from 'src/entities/flaskEntities/user.entity';
import { UserFamily } from 'src/entities/flaskEntities/userFamily.entity';
import { Family } from 'src/entities/flaskEntities/family.entity';
import { NeedEntity } from 'src/entities/need.entity';
import { NeedFamily } from 'src/entities/flaskEntities/needFamily';
import { PaymentEntity } from 'src/entities/payment.entity';
import { AllUserEntity } from 'src/entities/user.entity';

@Injectable()
export class FamilyService {
constructor(
@InjectRepository(NeedEntity)
private needRepository: Repository<NeedEntity>,
@InjectRepository(PaymentEntity)
private paymentRepository: Repository<PaymentEntity>,
@InjectRepository(AllUserEntity)
private allUserRepository: Repository<AllUserEntity>,
@InjectRepository(Need, 'flaskPostgres')
private flaskNeedRepository: Repository<Need>,
@InjectRepository(User, 'flaskPostgres')
Expand Down Expand Up @@ -134,7 +134,9 @@ export class FamilyService {
statusNotPaid: PaymentStatusEnum.COMPLETE_PAY,
})
.andWhere('need.isDeleted = :needDeleted', { needDeleted: false })
.andWhere(userId > 0 && `payment.id_user = :pUserId`, { pUserId: userId })
.andWhere(userId > 0 && `payment.id_user = :pUserId`, {
pUserId: userId,
})
.andWhere(userId > 0 && `needFamily.id_user = :nUserId`, {
nUserId: userId,
})
Expand Down Expand Up @@ -291,4 +293,11 @@ export class FamilyService {
.cache(10000)
.getMany();
}

async updateEmailMarketing(user: AllUserEntity): Promise<UpdateResult> {
const newStatus = user.monthlyEmail ? false : true;
return this.allUserRepository.update(user.id, {
monthlyEmail: newStatus,
});
}
}
3 changes: 2 additions & 1 deletion src/features/mail/mail.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { UserFamily } from 'src/entities/flaskEntities/userFamily.entity';
// or
transport: {
host: config.get('MAIL_HOST'),
secure: false,
secure: true,
auth: {
user: config.get('MAIL_FROM'),
pass: config.get('MAIL_PASSWORD'),
Expand Down Expand Up @@ -69,6 +69,7 @@ import { UserFamily } from 'src/entities/flaskEntities/userFamily.entity';
ChildrenPreRegisterEntity,
SignatureEntity,
PaymentEntity,
AllUserEntity,
]),
],
providers: [
Expand Down
Loading

0 comments on commit 1c6fb79

Please sign in to comment.