mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-25 18:08:40 -06:00
Work in progress of new text search endpoint
This commit is contained in:
parent
2c76098d59
commit
b3020fe9e0
@ -8,6 +8,14 @@ import { WAMonitoringService } from '../../../services/monitor.service';
|
||||
|
||||
const logger = new Logger('KwikController');
|
||||
|
||||
type SearchObject = {
|
||||
text_search: string;
|
||||
where: {
|
||||
owner: string;
|
||||
messageTimestamp: Record<string, any>; // Generic key-value pair
|
||||
}[];
|
||||
};
|
||||
|
||||
export class KwikController {
|
||||
constructor(private readonly waMonitor: WAMonitoringService) {}
|
||||
|
||||
@ -184,4 +192,39 @@ export class KwikController {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public async textSearch({ instanceName }: InstanceDto, query: SearchObject) {
|
||||
logger.error('request received in textSearch');
|
||||
logger.error(instanceName);
|
||||
logger.error(query);
|
||||
|
||||
const db = configService.get<Database>('DATABASE');
|
||||
const connection = dbserver.getClient().db(db.CONNECTION.DB_PREFIX_NAME + '-whatsapp-api');
|
||||
query.where.forEach((w) => {
|
||||
logger.error(w.messageTimestamp);
|
||||
logger.error(w.owner);
|
||||
});
|
||||
const messages = await connection
|
||||
.collection('messages')
|
||||
.find({
|
||||
// $and: [
|
||||
// {
|
||||
// $or: query.where,
|
||||
// },
|
||||
// {
|
||||
$text: { $search: query.text_search },
|
||||
// },
|
||||
// ],
|
||||
})
|
||||
.limit(10)
|
||||
.toArray();
|
||||
|
||||
// const conversations = messages.map((m) => `${m.owner}#${m.key.remoteJid}#${m.messageTimestamp}`);
|
||||
// logger.error('DELETEME: messages -> ');
|
||||
// logger.error(conversations);
|
||||
|
||||
// logger.error(messages.length);
|
||||
|
||||
return { messages };
|
||||
}
|
||||
}
|
||||
|
@ -70,6 +70,24 @@ export class KwikRouter extends RouterBroker {
|
||||
|
||||
return res.status(HttpStatus.OK).json(response);
|
||||
});
|
||||
|
||||
this.router.post(this.routerPath('textSearch'), ...guards, async (req, res) => {
|
||||
logger.verbose('request received in textSearch');
|
||||
logger.verbose('request body: ');
|
||||
logger.verbose(req.body);
|
||||
|
||||
logger.verbose('request query: ');
|
||||
logger.verbose(req.query);
|
||||
|
||||
const response = await this.dataValidate<InstanceDto>({
|
||||
request: req,
|
||||
schema: null,
|
||||
ClassRef: InstanceDto,
|
||||
execute: (instance) => kwikController.textSearch(instance, req.body),
|
||||
});
|
||||
|
||||
return res.status(HttpStatus.OK).json(response);
|
||||
});
|
||||
}
|
||||
|
||||
public readonly router = Router();
|
||||
|
Loading…
Reference in New Issue
Block a user