interface RequestModel<T> extends Request {
body: T
}
class UserRegisterModel {
first_name: string;
last_name: string;
email: string;
password: string;
constructor({first_name}) {
this.first_name = firstname;
// И так все НУЖНЫЕ поля
}
}
app.post('/register', async (req: RequestModel<UserRegisterModel>, res) => {
if(req.body) {
const user = new UserRegisterModel(req.body);
// Хоба и лишних полей нет ))
}
});
const data = [
{
id: 0,
type: 'Left',
count: 3,
accessories: {
aa: 'V S B',
bf: 'H',
dc: 'P E',
},
},
{
id: 1,
type: 'Right',
count: 2,
accessories: {
qw: 'L',
bm: 'K L',
},
},
];
const newData = data.map((item) => ({
name: `Name #${item.id}`,
attributes: Object.values(item.accessories).map((accessory) => ({
trait_type: 'accessory',
value: accessory,
})).concat([{
trait_type: 'type',
value: item.type,
}]),
}));
console.log(newData);
function onSubmit( form ){
var data = JSON.stringify( $(form).serializeArray() ); // <-----------
console.log( data );
return false; //don't submit
}
<form onsubmit='return onSubmit(this)'>
<input name='user' placeholder='user'><br>
<input name='password' type='password' placeholder='password'><br>
<button type='submit'>Try</button>
</form>
let obj = {
"viewport" : {
"key" : {
"lat" : 47,
"lng" : 39
},
"southwest" : {
"lat" : 47,
"lng" : 39
},
"one" : {
"keygen" : 47,
"lng" : 39
}
}
}
function deepSearch (object, key, predicate) {
if (object.hasOwnProperty(key)) {
return object
}
for (let i = 0; i < Object.keys(object).length; i++) {
if (typeof object[Object.keys(object)[i]] === 'object') {
let o = deepSearch(object[Object.keys(object)[i]], key)
if (o != null) return o
}
}
return null
}
const result = deepSearch(obj, 'keygen');
console.log(result); // {keygen: 47, lng: 39}