Browse Source
feat: add IsOnWhatsApp endpoint to check user availability
feat: add IsOnWhatsApp endpoint to check user availability
- Add /user/check endpoint with phone query parameter - Implement CheckRequest and CheckResponse domain types - Add IsOnWhatsApp method to user usecase interface and implementation - Create AccountUserCheck Vue component for UI interaction - Update OpenAPI documentation with new endpoint schema - Bump version to 6.1.0 for new feature releasepull/301/head
7 changed files with 183 additions and 3 deletions
-
51docs/openapi.yaml
-
8src/domains/user/account.go
-
1src/domains/user/user.go
-
17src/ui/rest/user.go
-
10src/usecase/user.go
-
95src/views/components/AccountUserCheck.js
-
4src/views/index.html
@ -0,0 +1,95 @@ |
|||||
|
import FormRecipient from "./generic/FormRecipient.js"; |
||||
|
|
||||
|
export default { |
||||
|
name: 'AccountUserCheck', |
||||
|
components: { |
||||
|
FormRecipient |
||||
|
}, |
||||
|
data() { |
||||
|
return { |
||||
|
type: window.TYPEUSER, |
||||
|
phone: '', |
||||
|
isOnWhatsApp: null, |
||||
|
loading: false, |
||||
|
} |
||||
|
}, |
||||
|
computed: { |
||||
|
phone_id() { |
||||
|
return this.phone + this.type; |
||||
|
} |
||||
|
}, |
||||
|
methods: { |
||||
|
async openModal() { |
||||
|
this.handleReset(); |
||||
|
$('#modalUserCheck').modal('show'); |
||||
|
}, |
||||
|
isValidForm() { |
||||
|
return this.phone.trim() !== ''; |
||||
|
}, |
||||
|
async handleSubmit() { |
||||
|
if (!this.isValidForm() || this.loading) { |
||||
|
return; |
||||
|
} |
||||
|
try { |
||||
|
await this.submitApi(); |
||||
|
showSuccessInfo("Check completed") |
||||
|
} catch (err) { |
||||
|
showErrorInfo(err) |
||||
|
} |
||||
|
}, |
||||
|
async submitApi() { |
||||
|
this.loading = true; |
||||
|
try { |
||||
|
let response = await window.http.get(`/user/check?phone=${this.phone_id}`) |
||||
|
this.isOnWhatsApp = response.data.results.is_on_whatsapp; |
||||
|
} catch (error) { |
||||
|
if (error.response) { |
||||
|
throw new Error(error.response.data.message); |
||||
|
} |
||||
|
throw new Error(error.message); |
||||
|
} finally { |
||||
|
this.loading = false; |
||||
|
} |
||||
|
}, |
||||
|
handleReset() { |
||||
|
this.phone = ''; |
||||
|
this.isOnWhatsApp = null; |
||||
|
this.type = window.TYPEUSER; |
||||
|
} |
||||
|
}, |
||||
|
template: `
|
||||
|
<div class="olive card" @click="openModal" style="cursor: pointer;"> |
||||
|
<div class="content"> |
||||
|
<a class="ui olive right ribbon label">Account</a> |
||||
|
<div class="header">User Check</div> |
||||
|
<div class="description"> |
||||
|
Check if a user is on WhatsApp |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
|
||||
|
<div class="ui small modal" id="modalUserCheck"> |
||||
|
<i class="close icon"></i> |
||||
|
<div class="header"> |
||||
|
Check if User is on WhatsApp |
||||
|
</div> |
||||
|
<div class="content"> |
||||
|
<form class="ui form"> |
||||
|
<FormRecipient v-model:type="type" v-model:phone="phone"/> |
||||
|
<button type="button" class="ui primary button" :class="{'loading': loading, 'disabled': !this.isValidForm() || this.loading}" |
||||
|
@click.prevent="handleSubmit"> |
||||
|
Check |
||||
|
</button> |
||||
|
</form> |
||||
|
|
||||
|
<div v-if="isOnWhatsApp !== null" class="ui message" :class="isOnWhatsApp ? 'positive' : 'negative'"> |
||||
|
<div class="header"> |
||||
|
<i :class="isOnWhatsApp ? 'check circle icon' : 'times circle icon'"></i> |
||||
|
{{ isOnWhatsApp ? 'User is on WhatsApp' : 'User is not on WhatsApp' }} |
||||
|
</div> |
||||
|
<p>Phone: {{ phone_id }}</p> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
`
|
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue