Compare commits
7 Commits
1.4.5-alph
...
developmen
Author | SHA1 | Date |
---|---|---|
|
064112e731 | |
|
d6a238a224 | |
|
dc5e938f75 | |
|
eb4da7ccc4 | |
|
46caaba6bd | |
|
7953c7dbbd | |
|
6911f6f0a2 |
|
@ -73,13 +73,14 @@ export class LoginAdminQueueManager extends BaseCustomManager<UserEntity> {
|
||||||
message: `Akun anda sudah login di item "${hasLoginAsQueue?.item_name}"`,
|
message: `Akun anda sudah login di item "${hasLoginAsQueue?.item_name}"`,
|
||||||
error: 'Unauthorized',
|
error: 'Unauthorized',
|
||||||
});
|
});
|
||||||
} else if (itemLogin && itemLogin.user_id !== this.userLogin.id) {
|
|
||||||
throw new UnauthorizedException({
|
|
||||||
statusCode: HttpStatus.UNAUTHORIZED,
|
|
||||||
message: `"${userLoginItem.name}" masih login sebagai admin antrian `,
|
|
||||||
error: 'Unauthorized',
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
// else if (itemLogin && itemLogin.user_id !== this.userLogin.id) {
|
||||||
|
// throw new UnauthorizedException({
|
||||||
|
// statusCode: HttpStatus.UNAUTHORIZED,
|
||||||
|
// message: `"${userLoginItem.name}" masih login sebagai admin antrian `,
|
||||||
|
// error: 'Unauthorized',
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
// * Disini untuk isi token
|
// * Disini untuk isi token
|
||||||
const tokenData = {
|
const tokenData = {
|
||||||
|
|
|
@ -19,6 +19,7 @@ export class CouchService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async onModuleInit() {
|
async onModuleInit() {
|
||||||
|
// return;
|
||||||
const nano = this.nanoInstance;
|
const nano = this.nanoInstance;
|
||||||
for (const database of DatabaseListen) {
|
for (const database of DatabaseListen) {
|
||||||
const db = nano.db.use(database);
|
const db = nano.db.use(database);
|
||||||
|
@ -95,4 +96,41 @@ export class CouchService {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getUnixTimestampLast7Days() {
|
||||||
|
const date = new Date();
|
||||||
|
date.setDate(date.getDate() - 4);
|
||||||
|
date.setHours(0, 0, 0, 0);
|
||||||
|
return date.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async clearTransactions() {
|
||||||
|
const nano = this.nanoInstance;
|
||||||
|
const transaction = nano.use('transaction');
|
||||||
|
|
||||||
|
const expiredDate = this.getUnixTimestampLast7Days();
|
||||||
|
|
||||||
|
const selectorPayment = {
|
||||||
|
created_at: {
|
||||||
|
$lt: expiredDate,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const transactions = await transaction.find({
|
||||||
|
selector: selectorPayment,
|
||||||
|
fields: ['_id', '_rev'],
|
||||||
|
limit: 100000,
|
||||||
|
});
|
||||||
|
|
||||||
|
const { docs } = transactions;
|
||||||
|
console.log(docs.length);
|
||||||
|
const deletedDocs = {
|
||||||
|
docs: docs.map((doc) => ({
|
||||||
|
_id: doc._id,
|
||||||
|
_rev: doc._rev,
|
||||||
|
_deleted: true,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
await transaction.bulk(deletedDocs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,17 @@ import { Public } from 'src/core/guards';
|
||||||
import * as Nano from 'nano';
|
import * as Nano from 'nano';
|
||||||
import { CreateUserPrivilegeDto } from 'src/modules/user-related/user-privilege/infrastructure/dto/create-user-privilege.dto';
|
import { CreateUserPrivilegeDto } from 'src/modules/user-related/user-privilege/infrastructure/dto/create-user-privilege.dto';
|
||||||
import { ConfigService } from '@nestjs/config';
|
import { ConfigService } from '@nestjs/config';
|
||||||
|
import { CouchService } from '../data/services/couch.service';
|
||||||
|
|
||||||
@ApiTags(`couch`)
|
@ApiTags(`couch`)
|
||||||
@Controller('v1/couch')
|
@Controller('v1/couch')
|
||||||
@Public()
|
@Public()
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CouchDataController {
|
export class CouchDataController {
|
||||||
constructor(private configService: ConfigService) {}
|
constructor(
|
||||||
|
private configService: ConfigService,
|
||||||
|
private couchService: CouchService,
|
||||||
|
) {}
|
||||||
|
|
||||||
get nanoInstance() {
|
get nanoInstance() {
|
||||||
const couchConfiguration = this.configService.get<string>('COUCHDB_CONFIG');
|
const couchConfiguration = this.configService.get<string>('COUCHDB_CONFIG');
|
||||||
|
@ -64,4 +68,11 @@ export class CouchDataController {
|
||||||
// return people.get();
|
// return people.get();
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Public(true)
|
||||||
|
@Get('clear-transactions')
|
||||||
|
async clearTransactions(): Promise<string> {
|
||||||
|
await this.couchService.clearTransactions();
|
||||||
|
return 'OK';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import { ItemQueueReadOrchestrator } from '../domain/usecases/item-queue-read.or
|
||||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||||
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
||||||
import { Public } from 'src/core/guards';
|
import { Public } from 'src/core/guards';
|
||||||
|
import { validate as isValidUUID } from 'uuid';
|
||||||
|
|
||||||
@ApiTags(`${MODULE_NAME.ITEM_QUEUE.split('-').join(' ')} - read`)
|
@ApiTags(`${MODULE_NAME.ITEM_QUEUE.split('-').join(' ')} - read`)
|
||||||
@Controller(`v1/${MODULE_NAME.ITEM_QUEUE}`)
|
@Controller(`v1/${MODULE_NAME.ITEM_QUEUE}`)
|
||||||
|
@ -50,7 +51,7 @@ export class ItemQueueReadController {
|
||||||
@Get('display/:id')
|
@Get('display/:id')
|
||||||
@Public(true)
|
@Public(true)
|
||||||
async detailPublic(@Param('id') id: string): Promise<ItemQueueEntity> {
|
async detailPublic(@Param('id') id: string): Promise<ItemQueueEntity> {
|
||||||
if (!id) throw new UnauthorizedException('id is required');
|
if (!isValidUUID(id)) throw new UnauthorizedException('id is required');
|
||||||
return await this.orchestrator.detail(id);
|
return await this.orchestrator.detail(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,10 @@ export class QueueAdminOrchestrator {
|
||||||
// },
|
// },
|
||||||
// ]);
|
// ]);
|
||||||
|
|
||||||
if (queueTicket.last_notification < currentTime - call_preparation) {
|
if (
|
||||||
|
queueTicket.item.ticket.phone != null &&
|
||||||
|
queueTicket.last_notification < currentTime - call_preparation
|
||||||
|
) {
|
||||||
await notification.queueProcess(payload);
|
await notification.queueProcess(payload);
|
||||||
this.service.updateLastNotification(queueId, currentTime);
|
this.service.updateLastNotification(queueId, currentTime);
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,6 +153,9 @@ export class GenerateQueueManager {
|
||||||
registerQueueManager.setService(this.queueService, TABLE_NAME.QUEUE);
|
registerQueueManager.setService(this.queueService, TABLE_NAME.QUEUE);
|
||||||
await registerQueueManager.execute();
|
await registerQueueManager.execute();
|
||||||
|
|
||||||
return registerQueueManager.getResult();
|
const result = await registerQueueManager.getResult();
|
||||||
|
result.time = null;
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import {
|
||||||
} from './whatsapp.constant';
|
} from './whatsapp.constant';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { Logger } from '@nestjs/common';
|
import { Logger } from '@nestjs/common';
|
||||||
|
import { apm } from 'src/core/apm';
|
||||||
|
|
||||||
export class WhatsappService {
|
export class WhatsappService {
|
||||||
async sendMessage(data) {
|
async sendMessage(data) {
|
||||||
|
@ -25,8 +26,14 @@ export class WhatsappService {
|
||||||
data: data,
|
data: data,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
const response = await axios(config);
|
const response = await axios(config);
|
||||||
return response.data;
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
Logger.error(error);
|
||||||
|
apm?.captureError(error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async queueRegister(data: WhatsappQueue) {
|
async queueRegister(data: WhatsappQueue) {
|
||||||
|
@ -91,8 +98,11 @@ export class WhatsappService {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
await this.sendMessage(payload);
|
const response = await this.sendMessage(payload);
|
||||||
Logger.log(`Notification register for ${data.code} send to ${data.phone}`);
|
if (response)
|
||||||
|
Logger.log(
|
||||||
|
`Notification register for ${data.code} send to ${data.phone}`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async queueProcess(data: WhatsappQueue) {
|
async queueProcess(data: WhatsappQueue) {
|
||||||
|
@ -152,7 +162,8 @@ export class WhatsappService {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
await this.sendMessage(payload);
|
const response = await this.sendMessage(payload);
|
||||||
|
if (response)
|
||||||
Logger.log(`Notification process for ${data.code} send to ${data.phone}`);
|
Logger.log(`Notification process for ${data.code} send to ${data.phone}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue