【发布时间】:2021-10-03 21:21:46
【问题描述】:
我想使用 user_id 从 api 获取笔记数据,但我无法访问我尝试记录但无法从 api 获取数据的 api。谁能帮我解决我在代码中缺少的东西
控制台检查错误我在获取数据时收到 404 错误。
状态:未找到
message: "http 的 Http 失败响应:
refresh(user_id){
this.isLoadingResults = true;
this.api.getdatachoice(user_id).subscribe(data =>{
this.studentData = data['items'];
console.log('studentData', this.studentData);
this.isLoadingResults = false;
})
this.filterInput
.valueChanges
.debounceTime(200)
.subscribe(term => {
this.filterText = term;
});
}
getdatachoice(user_id : any){
try{
const requestUrl = `${this.baseUrl}/api/admin/adminDashboard/getchoice=`+user_id;
return this.httpClient.get(requestUrl);
}catch(error){
this.handleError("getdatachoice : "+JSON.stringify(error));
}
}
router.get('/adminDashboard/getchoice', function (req, res) {
var students = [];
var course_name;
console.log("----------------------------fetched-------------------------------------");
// models.User.findById(req.user._id({
models.User.find({
where:{
userId : req.query.user_id,
id : req.body.user_id
}
}).models.Application.getUnsignedUser(req.body.user_id).then(data => {
require('async').eachSeries(data, function(student, callback){
var courieraddress;
if(student.isNewAddressSame == true || student.isNewAddressSame == "" ||
student.isNewAddressSame == null){
courieraddress = student.address;
}else{
courieraddress = student.newaddress
}
// models.User_Transcript.getCollegeName(student.user_id).then(function(colleges){
//
models.Institution_details.getAllInstitutionType(student.user_id).then(function(types){
models.Applicant_Educational_Details.getCourseName(student.user_id).then(function
name(edu_details) {
if(edu_details.length > 0){
course_name = edu_details ? edu_details[0].Course_full_name : '';
//console.log("course_name---->"+course_name);
}else{
course_name = '';
}
students.push({
id : student.id,
name :student.name,
email : student.email,
user_id : student.user_id,
university_name: student.university,
transcript_name: student.tcname,
student.instruction_medium : '--' ,
application_date : moment(new
Date(student.created_at)).format("DD/MM/YYYY"),
recepientsname :student.name,
courieraddress : courieraddress,
noOfCopies : student.numofcouriers,
couremail : student.couremail,
courmobile : student.courmobile,
newemail : student.newemail,
studentsAction : (student.preferredoptionfortranscriptdownload) ?
student.preferredoptionfortranscriptdownload : 'Email',
course_name : course_name,
notes : student.notes ,
education_lock : student.education_lock ? student.education_lock : 'true',
course_short_form :edu_details[0] ? edu_details[0].CourseName : '',
enrollmentYear : student.enrollmentYear,
enrollmentYearStandard : student.enrollmentYearStandard,
leavingYear : student.leavingYear,
leavingYearStandard : student.leavingYearStandard
});
callback();
});
// });
// });
}, function(){
res.json({
status: 200,
message: 'Student retrive successfully',
items : students,
total_count : students.length
});
});
});
});
【问题讨论】:
-
如果您可以将代码减少到尽可能少的数量以显示问题,那就太好了。例如,只需让您的端点返回“hello world”响应。那么人们会更容易帮助你。
标签: node.js angular mongodb express mongoose