-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix-1308: Fix hash_from and hash_to is equal in user_contact
- Loading branch information
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...ontact-service/src/db/ContactDbService/queries/createDeleteContactsByHashFromAndHashTo.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import {Schema} from '@effect/schema' | ||
import {SqlSchema} from '@effect/sql' | ||
import {PgClient} from '@effect/sql-pg' | ||
import {UnexpectedServerError} from '@vexl-next/domain/src/general/commonErrors' | ||
import {HashedPhoneNumberE} from '@vexl-next/domain/src/general/HashedPhoneNumber.brand' | ||
import {Effect, flow} from 'effect' | ||
|
||
const DeleteContactsByHashFromAndHashToQuery = Schema.Struct({ | ||
hashFrom: HashedPhoneNumberE, | ||
hashTo: HashedPhoneNumberE, | ||
}) | ||
|
||
export type DeleteContactsByHashFromAndHashToQuery = Schema.Schema.Type< | ||
typeof DeleteContactsByHashFromAndHashToQuery | ||
> | ||
|
||
export const createDeleteContactsByHashFromAndHashTo = Effect.gen( | ||
function* (_) { | ||
const sql = yield* _(PgClient.PgClient) | ||
|
||
const query = SqlSchema.void({ | ||
Request: DeleteContactsByHashFromAndHashToQuery, | ||
execute: (hash) => sql` | ||
DELETE FROM user_contact | ||
WHERE | ||
hash_from = ${hash.hashFrom} | ||
AND hash_to = ${hash.hashTo} | ||
`, | ||
}) | ||
|
||
return flow( | ||
query, | ||
Effect.catchAll((e) => | ||
Effect.zipRight( | ||
Effect.logError('Error in deleteContactsByHashFromAndHashTo', e), | ||
Effect.fail(new UnexpectedServerError({status: 500})) | ||
) | ||
), | ||
Effect.withSpan('deleteContactsByHashFromAndHashTo query') | ||
) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters