Skip to content

Commit

Permalink
add send sms for post
Browse files Browse the repository at this point in the history
  • Loading branch information
bahram1249 committed Jun 18, 2024
1 parent 6a389ec commit e3d5dab
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import { User } from '@rahino/database/models/core/user.entity';
import { Permission } from '@rahino/database/models/core/permission.entity';
import { ECOrder } from '@rahino/database/models/ecommerce-eav/ec-order.entity';
import { UtilOrderModule } from '../utilOrder/util-order.module';
import { ECommerceSmsModule } from '@rahino/ecommerce/util/sms/ecommerce-sms.module';

@Module({
imports: [
SequelizeModule.forFeature([User, Permission, ECOrder]),
UtilOrderModule,
ECommerceSmsModule,
],
controllers: [PostageOrderController],
providers: [PostageOrderService],
Expand Down
14 changes: 14 additions & 0 deletions apps/e-commerce/src/admin/postageOrder/postage-order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Op } from 'sequelize';
import { OrderUtilService } from '../utilOrder/service/order-util.service';
import { I18nContext, I18nService } from 'nestjs-i18n';
import { I18nTranslations } from 'apps/main/src/generated/i18n.generated';
import { ECommmerceSmsService } from '@rahino/ecommerce/util/sms/ecommerce-sms.service';

@Injectable()
export class PostageOrderService {
Expand All @@ -23,6 +24,7 @@ export class PostageOrderService {
private readonly repository: typeof ECOrder,
private orderQueryBuilder: OrderQueryBuilder,
private orderUtilService: OrderUtilService,
private readonly smsService: ECommmerceSmsService,
private readonly i18n: I18nService<I18nTranslations>,
) {}

Expand Down Expand Up @@ -97,6 +99,12 @@ export class PostageOrderService {
},
),
)
.include([
{
model: User,
as: 'user',
},
])
.build(),
);
if (!item) {
Expand All @@ -110,6 +118,12 @@ export class PostageOrderService {
item.postReceipt = dto.postReceipt;
item.deliveryDate = new Date();
item = await item.save();

await this.smsService.sendByPost(
`${item.user.firstname};${item.user.lastname};اداره پست;${dto.postReceipt}`,
item.user.phoneNumber,
);

return {
result: item,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class ProductCommentController {
@ApiOperation({ description: 'show all possible factors' })
@Get('/possibleFactor/:productId')
@HttpCode(HttpStatus.OK)
async possibleFactors(@Param('id') productId: bigint) {
async possibleFactors(@Param('productId') productId: bigint) {
return await this.service.possibleFactors(productId);
}

Expand Down
16 changes: 16 additions & 0 deletions apps/e-commerce/src/util/sms/ecommerce-sms.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ export class ECommmerceSmsService {
}
}

async sendByPost(text: string, to: string) {
/*
{0} {1} عزیز، سفارش شما توسط {2} با کدپیگیری {3} با موفقیت ارسال شد
*/
const activeSms =
(await this.config.get('ECOMMERCE_POST_SEND_SMS_CODE_STATUS')) == 'true';
if (activeSms == true) {
const body = this.config.get('ECOMMERCE_POST_SEND_SMS_CODE');
await this.smsService.sendMessage({
text: text,
to: to,
bodyId: body,
});
}
}

async successfulPayment(text: string, to: string) {
/*
{0} {1} عزیز سفارش شما با شماره {2} در تاریخ {3} ثبت و پرداخت شد. جهیزان
Expand Down

0 comments on commit e3d5dab

Please sign in to comment.