typescript/kuzzle + elastic search

커즐(kuzzle) 활용 예시 5(아이디/닉네임 중복확인) v5.x

노래하는 마케터 2019. 2. 26. 09:54
728x90
confirmOverlapId() {
this.kuzzle
.collection('collection_name', 'index_name')
.fetchDocument(this.userid, async function (error, result) {
if (error && this.userid.length !== 0) {
const alertId = await this.alertCtrl.create({
header: '아이디 중복확인',
message: '사용 가능합니다.',
buttons: [
{
text: '확인',
handler: data => {
this.posUserId = true;
}
}]
});
return await alertId.present();
} else if (result) {
const alert = await this.alertCtrl.create({
header: '아이디 중복확인',
message: '다시 입력해주세요.',
inputs: [
{
name: 'userid',
value: this.userid
}],
buttons: [
{
text: '취소',
role: '취소',
},
{
text: '확인',
handler: data => {
this.userid = data.userid;
this.posUserId = false;
}
}]
});
return await alert.present();
}
}.bind(this));
}

confirmOverlapNickname() {
const body = {
'query': {
'match': {
'USER_NICKNAME': this.usernickname
}
}
};
const options = {
from: 0
};
this.kuzzle
.collection('collection_name', 'index_name')
.search(body, options, async function (err, searchResult) {
if (searchResult.documents.length === 0) {
const alertNickname = await this.alertCtrl.create({
header: '닉네임 중복확인',
message: '사용 가능합니다.',
buttons: [
{
text: '확인',
handler: data => {
this.posUserNickname = true;
}
}]
});
return await alertNickname.present();
} else if (searchResult.documents.length === 1) {
const alert = await this.alertCtrl.create({
header: '닉네임 중복확인',
message: '다시 입력해주세요.',
inputs: [
{
name: 'usernickname',
value: this.usernickname
}],
buttons: [
{
text: '취소',
role: '취소',
},
{
text: '확인',
handler: data => {
this.usernickname = data.usernickname;
this.posUserNickname = false;
}
}]
});
return await alert.present();
}
}.bind(this));
}


728x90