gpt4 book ai didi

javascript - 如何使用云代码和 Shashido 在按钮单击时更改解析 Angular 色数组?

转载 作者:行者123 更新时间:2023-12-01 04:02:34 24 4
gpt4 key购买 nike

如果单击该函数并且我必须在云代码中对其进行编码,我需要将数组的值从“User”更改为“Admin”。

但是有一个问题,数组没有改变

以下代码可以工作,但只有 nameRoleQuery 的部分不起作用,这就是我需要更改的部分。

promoteToAdmin: function promoteToAdmin(request, response) {
if (!request.params.companyUser) {
response.error('Request did not have an authenticated user attached with it');
} else {
var companyUser;
var companyUserQuery = new Parse.Query('CompanyUser');
companyUserQuery.include('user');
companyUserQuery.include('company');
companyUserQuery.get(request.params.companyUser, {
useMasterKey: true
}).then((giveRolename) => {
var nameRoleQuery = new Parse.Query(Parse.Role);
request.nameRoleQuery.set('user', ['Admin']);
return nameRoleQuery.save(null, {
useMasterKey: true
});
}).then((companyUserObject) => {
companyUser = companyUserObject;
var userRoleQuery = new Parse.Query(Parse.Role);
userRoleQuery.equalTo('name', 'Company-User-' + companyUser.get('company').id);
return userRoleQuery.first({
useMasterKey: true
});
}).then((userRole) => {
var usersInUserRole = userRole.relation('users');
usersInUserRole.remove(companyUser.get('user'));
return userRole.save(null, {
useMasterKey: true
});
}).then((userRoleSaveResult) => {
var adminRoleQuery = new Parse.Query(Parse.Role);
adminRoleQuery.equalTo('name', 'Company-Admin-' + companyUser.get('company').id);
return adminRoleQuery.first({
useMasterKey: true
});
}).then((adminRole) => {
var usersInAdminRole = adminRole.relation('users');
usersInAdminRole.add(companyUser.get('user'));
return adminRole.save(null,{
useMasterKey: true
});
}).then((saveResult) => {
console.log('after');
response.success('fissa is aan');
}, (error) => {
console.log(error);
});
console.log();
}

}

enter image description here

Angular 色数组需要更改。

最佳答案

仍然不确定你到底想做什么,但这就是我想你想要发生的事情。

CompanyUser 有一个名为“user”、类型为 Parse.User 的指针。当您运行此查询时,您希望根据您的图像更新此 Parse.User。以下内容应该有效:

        //AS ABOVE
.then((giveRolename) => {
var user = giveRoleName.get("user");
user.remove('role','user');
user.add('role','admin');
return user.save(null, {useMasterKey:true});
}).then((companyUserObject) => {
//companyUserObject is Parse.User object. If CompanyUser object is needed, store in variable beforehand.

我在下面列出了我对当前代码的改进建议。它的顺序性较差,并且在流程中间发生错误时提供了更大的后备。它没有箭头功能,因此您必须进行相应的更改。

function promoteToAdmin(request, response) {

var params = request.params;
var companyUserId = params["companyUser"];

var companyUser;

return Parse.Promise.as().then(
function()
{
if(!companyUser)
{
return Parse.Promise.error("Request did not have an user attached with it.");
}
var CompanyUser = Parse.Object.extend("CompanyUser");
var companyUserQuery = new Parse.Query(CompanyUser);
companyUserQuery.include("user");
companyUserQuery.include("company");
return companyUserQuery.get(companyUserId,{useMasterKey:true});

}
).then(
function(fetchedCompanyUser)
{
companyUser = fetchedCompanyUser;
var company = companyUser.get("company");

var userRoleQuery = new Parse.Query(Parse.Role);
userRoleQuery.equalTo('name', "Company-User-" + company.id )

var adminRoleQuery = new Parse.Query(Parse.Role);
adminRoleQuery.equalTo('name', "Company-Admin-" + company.id);


return Parse.Promise.when(
userRoleQuery.first({useMasterKey:true}),
adminRoleQuery.first({useMasterKey:true})
)

}
).then(
function(userRole,adminRole)
{
if(!userRole || !adminRole)
{
return Parse.Promise.error("No role found")
}

var user = companyUser.get("user");

user.remove("role","user");
user.add("role","admin");

userRole.getUsers().remove(user);
adminRole.getUsers().add(user);


return Parse.Promise.when(
user.save(null,{useMasterKey:true}),
userRole.save(null,{useMasterKey:true}),
adminRole.save(null,{useMasterKey:true})
)

}
).then(
function(user,userRole,adminRole)
{
response.success("success");
},
function(error)
{
response.error(error);
}
)

}

关于javascript - 如何使用云代码和 Shashido 在按钮单击时更改解析 Angular 色数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42088186/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com