You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
782 B
JavaScript
31 lines
782 B
JavaScript
"use strict";
|
|
|
|
const matchValue = require("../match-value");
|
|
|
|
module.exports = function validateUserIdentifier(userIdentifier) {
|
|
let {assertProperties, isPresent, isString, isOneOf} = require("../validator-lib");
|
|
|
|
assertProperties(userIdentifier, {
|
|
type: [ isPresent, isOneOf("m.id.user", "m.id.thirdparty", "m.id.phone") ]
|
|
});
|
|
|
|
matchValue(userIdentifier.type, {
|
|
"m.id.user": () => {
|
|
assertProperties(userIdentifier, {
|
|
user: [ isPresent, isString ]
|
|
});
|
|
},
|
|
"m.id.thirdparty": () => {
|
|
assertProperties(userIdentifier, {
|
|
medium: [ isPresent, isString ],
|
|
address: [ isPresent, isString ]
|
|
});
|
|
},
|
|
"m.id.phone": () => {
|
|
assertProperties(userIdentifier, {
|
|
country: [ isPresent, isString ],
|
|
phone: [ isPresent, isString ]
|
|
});
|
|
}
|
|
});
|
|
}; |