Skip to content

Commit

Permalink
Merge pull request #1094 from salitha-pathi/fix/postgres-invalid-ctx-…
Browse files Browse the repository at this point in the history
…phone

fix(adapter): 🐛 incorrect `HistoryEntry` on PostgreSQL Adaptor
  • Loading branch information
leifermendez authored Aug 23, 2024
2 parents 48f0284 + efa9aa2 commit 5858312
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/database-postgres/__tests__/ postgresAdapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const historyMock: HistoryEntry = {
keyword: 'exampleKeyword',
answer: 'exampleAnswer',
refSerialize: 'exampleRefSerialize',
phone: '123456789',
from: '123456789',
options: {
option1: 'value1',
option2: 42,
Expand Down Expand Up @@ -83,7 +83,7 @@ test('getPrevByNumber - getPrevByNumber returns the previous history entry', asy
}

const result = await postgreSQLAdapter.getPrevByNumber(from)
assert.is(result?.phone, historyMock.phone)
assert.is(result?.from, historyMock.from)
assert.is(result?.ref, historyMock.ref)
assert.is(result?.refSerialize, undefined)
})
Expand Down
4 changes: 2 additions & 2 deletions packages/database-postgres/src/postgresAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class PostgreSQLAdapter extends MemoryDB {
}

async save(ctx: HistoryEntry): Promise<void> {
const values = [ctx.ref, ctx.keyword, ctx.answer, ctx.refSerialize, ctx.phone, JSON.stringify(ctx.options)]
const values = [ctx.ref, ctx.keyword, ctx.answer, ctx.refSerialize, ctx.from, JSON.stringify(ctx.options)]
const query = `SELECT save_or_update_history_and_contact($1, $2, $3, $4, $5, $6)`

try {
Expand All @@ -60,7 +60,7 @@ class PostgreSQLAdapter extends MemoryDB {
}

async getContact(ctx: HistoryEntry): Promise<Contact | undefined> {
const from = ctx.phone
const from = ctx.from
const query = `SELECT * FROM public.contact WHERE phone = $1 LIMIT 1`
try {
const result = await this.db.query(query, [from])
Expand Down
2 changes: 1 addition & 1 deletion packages/database-postgres/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export type HistoryEntry = {
keyword?: string
answer: string
refSerialize: string
phone: string
from: string
options?: Record<string, any>
}

Expand Down

0 comments on commit 5858312

Please sign in to comment.