mirror of
https://github.com/hexastack/hexabot
synced 2024-11-24 04:53:41 +00:00
refactor: move getContextVarsByBlock to ContextVarService
This commit is contained in:
parent
6e8a2a3d48
commit
92003c471e
@ -12,6 +12,7 @@ import { Injectable } from '@nestjs/common';
|
||||
import { BaseService } from '@/utils/generics/base-service';
|
||||
|
||||
import { ContextVarRepository } from '../repositories/context-var.repository';
|
||||
import { Block, BlockFull } from '../schemas/block.schema';
|
||||
import { ContextVar } from '../schemas/context-var.schema';
|
||||
|
||||
@Injectable()
|
||||
@ -19,4 +20,17 @@ export class ContextVarService extends BaseService<ContextVar> {
|
||||
constructor(readonly repository: ContextVarRepository) {
|
||||
super(repository);
|
||||
}
|
||||
|
||||
async getContextVarsByBlock(
|
||||
block: Block | BlockFull,
|
||||
): Promise<Record<string, ContextVar>> {
|
||||
return (
|
||||
await this.find({
|
||||
name: { $in: block.capture_vars.map((cv) => cv.context_var) },
|
||||
})
|
||||
).reduce((acc, cv) => {
|
||||
acc[cv.name] = cv;
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ import { SubscriberService } from './subscriber.service';
|
||||
import { VIEW_MORE_PAYLOAD } from '../helpers/constants';
|
||||
import { ConversationRepository } from '../repositories/conversation.repository';
|
||||
import { Block, BlockFull } from '../schemas/block.schema';
|
||||
import { ContextVar } from '../schemas/context-var.schema';
|
||||
import {
|
||||
Conversation,
|
||||
ConversationFull,
|
||||
@ -92,17 +91,8 @@ export class ConversationService extends BaseService<
|
||||
convo.context.nlp = event.getNLP();
|
||||
convo.context.vars = convo.context.vars || {};
|
||||
|
||||
const contextVars = (
|
||||
await this.contextVarService.find({
|
||||
name: { $in: next.capture_vars.map((c) => c.context_var) },
|
||||
})
|
||||
).reduce(
|
||||
(acc, cv) => {
|
||||
acc[cv.name] = cv;
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, ContextVar>,
|
||||
);
|
||||
const contextVars =
|
||||
await this.contextVarService.getContextVarsByBlock(next);
|
||||
|
||||
// Capture user entry in context vars
|
||||
if (captureVars && next.capture_vars && next.capture_vars.length > 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user