Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async submit() {
this.formLocked = true;
const user = this.form.value;
user.phone = this.tmpPhone;
user.countryCallingCode = this.tmpCountryCallingCode;
user.mode = this.userMode;
this.helper = null;
let promise;
if (this.mode === 'edit') {
const cleaned: ApiPutUserObject = updatedDiff(Object.assign({ password: undefined }, this.user), replaceInObject(user, '', null));
const alreadyExist = cleaned.identity && (cleaned.identity.commonName || cleaned.identity.organization)
? await this.checkSealIdentity(user) : false;
if (alreadyExist) {
if (!confirm('This seal identity already exists.\n'
+ 'Do you still want to update it?')) {
this.formLocked = false;
return;
}
}
promise = this.service.update(this.user.id, cleaned)
.then((up) => this.submitSucceed.emit(up));
} else {
user.createDefaultKey = this.createDefaultKey;
if (this.sendPasswordEmail) {
user.password = null;
} else {
const [_existedProfile] = await client.getMessengerProfile(FIELDS);
const profile = trimDomain(_profile);
const existedProfile = trimDomain(_existedProfile);
const diffResult = diff(existedProfile, profile);
if (Object.keys(diffResult).length !== 0) {
const shouldDeleteFields = Object.keys(
deletedDiff(existedProfile, profile)
);
const shouldSetFields = [
...Object.keys(addedDiff(existedProfile, profile)),
...Object.keys(updatedDiff(existedProfile, profile)),
];
if (shouldDeleteFields.length > 0) {
await client.deleteMessengerProfile(
shouldDeleteFields.map(field => snakecase(field))
);
const deleteFileds = shouldDeleteFields.join(', ');
print(`Successfully delete ${bold(deleteFileds)} settings`);
}
if (shouldSetFields.length > 0) {
const shouldSetProfile = pick(profile, shouldSetFields);
if (shouldSetFields.includes('whitelistedDomains')) {
await client.setMessengerProfile(
pick(shouldSetProfile, 'whitelistedDomains')