Skip to content

Commit

Permalink
chore: Improve code consistency and readability
Browse files Browse the repository at this point in the history
Refactored the initialization of `LocalSettings` in `channel.service.ts` to only set the properties that have been explicitly provided. This refactoring improves code consistency and readability. Also, removed the unused `initStoreFolders` method from `repository.service.ts` and its related imports. In addition, updated the import style for `PrismaClient` in `repository.service.ts`.

The modified files are:
- src/api/controllers/instance.controller.ts
- src/api/repository/repository.service.ts
- src/api/services/channel.service.ts
- src/api/services/channels/whatsapp.baileys.service.ts
  • Loading branch information
dgcode-tec committed Jun 27, 2024
1 parent 457628b commit 228dcf8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 36 deletions.
12 changes: 6 additions & 6 deletions src/api/controllers/instance.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,13 @@ export class InstanceController {
}

const settings: wa.LocalSettings = {
rejectCall: rejectCall || false,
rejectCall: rejectCall === true,
msgCall: msgCall || '',
groupsIgnore: groupsIgnore || true,
alwaysOnline: alwaysOnline || false,
readMessages: readMessages || false,
readStatus: readStatus || false,
syncFullHistory: syncFullHistory ?? false,
groupsIgnore: groupsIgnore === true,
alwaysOnline: alwaysOnline === true,
readMessages: readMessages === true,
readStatus: readStatus === true,
syncFullHistory: syncFullHistory === true,
};

await this.settingsService.create(instance, settings);
Expand Down
26 changes: 0 additions & 26 deletions src/api/repository/repository.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { PrismaClient } from '@prisma/client';
import fs from 'fs';
import { join } from 'path';

import { ConfigService } from '../../config/env.config';
import { Logger } from '../../config/logger.config';
Expand All @@ -15,30 +13,6 @@ export class Query<T> {
export class PrismaRepository extends PrismaClient {
constructor(private readonly configService: ConfigService) {
super();

this.initStoreFolders();
}

private async initStoreFolders() {
try {
const storePath = join(process.cwd(), 'store');

this.logger.verbose('creating store path: ' + storePath);

const tempDir = join(storePath, 'temp');
const chatwootDir = join(storePath, 'chatwoot');

if (!fs.existsSync(chatwootDir)) {
this.logger.verbose('creating chatwoot dir: ' + chatwootDir);
fs.mkdirSync(chatwootDir, { recursive: true });
}
if (!fs.existsSync(tempDir)) {
this.logger.verbose('creating temp dir: ' + tempDir);
fs.mkdirSync(tempDir, { recursive: true });
}
} catch (error) {
this.logger.error(error);
}
}

private readonly logger = new Logger(PrismaRepository.name);
Expand Down
8 changes: 7 additions & 1 deletion src/api/services/channel.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,13 @@ export class ChannelStartupService {
},
});

Object.assign(this.localSettings, data);
this.localSettings.rejectCall = data?.rejectCall;
this.localSettings.msgCall = data?.msgCall;
this.localSettings.groupsIgnore = data?.groupsIgnore;
this.localSettings.alwaysOnline = data?.alwaysOnline;
this.localSettings.readMessages = data?.readMessages;
this.localSettings.readStatus = data?.readStatus;
this.localSettings.syncFullHistory = data?.syncFullHistory;
}

public async findSettings() {
Expand Down
7 changes: 4 additions & 3 deletions src/api/services/channels/whatsapp.baileys.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ export class BaileysStartupService extends ChannelStartupService {
public async getProfileStatus() {
const status = await this.client.fetchStatus(this.instance.wuid);

return status[0]?.status;
return status?.status;
}

public get profilePictureUrl() {
Expand Down Expand Up @@ -551,6 +551,8 @@ export class BaileysStartupService extends ChannelStartupService {

this.logger.info(log);

this.logger.info(`Group Ignore: ${this.localSettings.groupsIgnore}`);

let options;

if (this.localProxy.enabled) {
Expand Down Expand Up @@ -625,7 +627,6 @@ export class BaileysStartupService extends ChannelStartupService {
},
userDevicesCache: this.userDevicesCache,
transactionOpts: { maxCommitRetries: 5, delayBetweenTriesMs: 2500 },
// forceGroupsPrekey: false,
patchMessageBeforeSending(message) {
if (
message.deviceSentMessage?.message?.listMessage?.listType ===
Expand Down Expand Up @@ -1667,7 +1668,7 @@ export class BaileysStartupService extends ChannelStartupService {
try {
return {
wuid: jid,
status: (await this.client.fetchStatus(jid))[0]?.status,
status: (await this.client.fetchStatus(jid))?.status,
};
} catch (error) {
return {
Expand Down

0 comments on commit 228dcf8

Please sign in to comment.