Skip to content

Commit

Permalink
Merge pull request #7 from ssysm/update
Browse files Browse the repository at this point in the history
update Funding db model and update to v1.0.2
  • Loading branch information
ssysm authored Jan 29, 2018
2 parents c4f2fb8 + 356dec4 commit 8934b9c
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 43 deletions.
2 changes: 1 addition & 1 deletion client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions client/src/app/service/funding.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ export class FundingService {
.post(environment.apiBase+'/funding/create',data)
}

deleteFundRecord(uid:String){
deleteFundRecord(activity_id,uid:String){
return this.http
.delete(environment.apiBase+'/funding/delete',new RequestOptions({
body: {uid:uid}
body: {activity_id:activity_id,uid:uid}
}))
}

Expand Down
6 changes: 3 additions & 3 deletions client/src/app/view/about/about.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ <h1 class="text-center introh1 h1">关于我们</h1>
</blockquote>
<div class="row" id="sysInfo">
<div class="col-sm-12">
<h3>系统版本号: <span class="badge badge-success">v1.0.1</span></h3>
<h3>系统版本号: <span class="badge badge-success">v1.0.2</span></h3>
<div style="display: inline">
<p style="display: inline">前端: <span class="badge badge-success">v1.0.1</span></p>
<p style="display: inline">后端: <span class="badge badge-success">v1.0.1</span></p>
<p style="display: inline">前端: <span class="badge badge-success">v1.0.2</span></p>
<p style="display: inline">后端: <span class="badge badge-success">v1.0.2</span></p>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class ActivityDetailComponent implements OnInit {
this.content = data.json().response.content.replace(/\n/g, "<br/>");
this.fundingService.fetchFundingList(this.activityId)
.subscribe(funding=>{
this.fundArr = funding.json().response;
this.fundArr = funding.json().response.record;
})
}else{
this.router.navigate(['/404'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<tr *ngFor="let fund of fundArr">
<td>{{fund.name}}</td>
<td>{{fund.amount}}</td>
<td><a style="color: red" (click)="deleteFund(fund._id)">删除</a></td>
<td><a style="color: red" (click)="deleteFund(fundId,fund._id)">删除</a></td>
</tr>
</tbody>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ export class FundingManagementComponent implements OnInit {
updateFundTable(){
this.fundingService.fetchFundingList(this.fundId)
.subscribe(data=>{
this.fundArr = data.json().response
this.fundArr = data.json().response.record
})
}

deleteFund(uid:String){
this.fundingService.deleteFundRecord(uid)
deleteFund(activity_id,uid:String){
this.fundingService.deleteFundRecord(activity_id,uid)
.subscribe(data=>{
if(data.json().success){
alert('删除成功');
Expand All @@ -62,8 +62,8 @@ export class FundingManagementComponent implements OnInit {
addFund(data){
this.fundingService.createFundRecord(data)
.subscribe(data=>{
this.fundArr.push(data.json().response);
$('#addFund').modal('hide');
location.reload();
})
}

Expand Down
42 changes: 36 additions & 6 deletions server/actions/activity.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//Import Activity Schema and mongoose
const Activity = require('../models/Activity');
const Funding = require('../models/Funding');
const mongoose = require('mongoose');
//Create an activity
//@method:POST
Expand All @@ -16,9 +17,24 @@ createActivity = (req,res)=>{
response:err
})
}else{
res.status(200).json({
success:true,
response:docs
Funding.create({
activity_id:docs._id
},(err2,fund)=>{
if(err2){
res.status(500).json({
success:false,
response:err2
})
}
else{
res.status(200).json({
success:true,
response:{
q1:docs,
q2:fund
}
})
}
})
}
})
Expand Down Expand Up @@ -90,9 +106,23 @@ deleteActivity = (req,res)=>{
response:err
})
}else{
res.status(200).json({
success:true,
response:docs
Funding.remove({
activity_id:req.body.uid
},(err2,fund)=>{
if(err2){
res.status(500).json({
success:false,
response:err2
})
}else{
res.status(200).json({
success:true,
response:{
q1:docs,
q2:fund
}
})
}
})
}
})
Expand Down
22 changes: 14 additions & 8 deletions server/actions/funding.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const mongoose = require('mongoose');
fetchFundById = (req,res)=>{
"use strict";
var { activity_id } = req.query;
Funding.find({
Funding.findOne({
activity_id
},(err,docs)=>{
if(err){
Expand Down Expand Up @@ -37,17 +37,23 @@ fetchFundById = (req,res)=>{
createFundRecord = (req,res)=>{
"use strict";
var { activity_id,name,amount,message } = req.body;
const data = {activity_id, name, amount, message};
Funding.create(data,(err,docs)=>{
const data = {name, amount, message};
Funding.update({
activity_id:mongoose.Types.ObjectId(activity_id)
},{
$push:{
record:data
}
},(err,funding)=>{
if(err){
res.status(500).json({
success:false,
response:err
})
}else{
res.status(200).json({
res.json({
success:true,
response:docs
response:funding
})
}
})
Expand All @@ -58,9 +64,9 @@ createFundRecord = (req,res)=>{
//@return:JSON Object
deleteFundRecord = (req,res)=>{
"use strict";
Funding.remove({
_id:mongoose.Types.ObjectId(req.body.uid)
},(err,docs)=>{
Funding.update({
activity_id:req.body.activity_id
}, { $pull: { record:{_id:mongoose.Types.ObjectId(req.body.uid) } } } ,{ multi: true },(err,docs)=>{
if(err){
res.status(500).json({
success:false,
Expand Down
13 changes: 9 additions & 4 deletions server/migrate.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
//链接数据库
const mongoose = require('mongoose');
mongoose.connect(require('./config').database);
const User = require('./models/User');
const bcrypt = require('bcrypt-nodejs');
//插入转移信息
const password = 'password';
//转换对象
const data = {
username:'admin',
password:bcrypt.hashSync('password')
password:bcrypt.hashSync(password)
};
//插入
User.create(data,(err,docs)=>{
"use strict";
if(err) throw err;
else {
console.log(docs);
console.log("移植初始化完成,请退出");
return true;
console.log("移植初始化完成");
process.exit();
}
});
});
22 changes: 11 additions & 11 deletions server/models/Funding.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ const schema = mongoose.Schema({
type:String,
required:true
},
name:{
type:String,
required:true
},
amount:{
type:Number,
required:true
},
message:{
type:String
}
record:[{
name:{
type:String,
},
amount:{
type:Number,
},
message:{
type:String
}
}]
});

module.exports = mongoose.model('funding',schema);
2 changes: 1 addition & 1 deletion server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "server",
"version": "1.0.1",
"version": "1.0.2",
"scripts": {
"start": "node ./bin/www",
"dev": "nodemon ./bin/www"
Expand Down

0 comments on commit 8934b9c

Please sign in to comment.