Skip to content

Commit 1176651

Browse files
authored
Merge pull request #207 from boostcamp-2020/develop
4주차 배포 Hotfix
2 parents 1786eed + d3ead0a commit 1176651

File tree

106 files changed

+2274
-214
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+2274
-214
lines changed

be/src/controllers/account/index.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,38 @@ export const get = async (ctx: Koa.Context) => {
88

99
if (!res) {
1010
ctx.status = 204;
11-
ctx.response.body = [];
1211
return;
1312
}
1413
ctx.status = 200;
1514
ctx.response.body = res;
1615
};
1716

17+
export const postAccount = async (ctx: Koa.Context) => {
18+
await accountService.addAccountByUserAndAccountInfo(
19+
ctx.request.body.user,
20+
ctx.request.body.title,
21+
ctx.request.body.userObjIdList,
22+
);
23+
ctx.status = 201;
24+
ctx.response.body = { success: true };
25+
};
26+
27+
export const putAccount = async (ctx: Koa.Context) => {
28+
await accountService.updateAccountByUserAndAccountInfo(
29+
ctx.request.body.title,
30+
ctx.params.accountObjId,
31+
ctx.request.body.userObjIdList,
32+
);
33+
ctx.status = 200;
34+
ctx.response.body = { success: true };
35+
};
36+
37+
export const deleteAccount = async (ctx: Koa.Context) => {
38+
await accountService.deleteAccountByAccountInfo(ctx.params.accountObjId);
39+
ctx.status = 200;
40+
ctx.response.body = { success: true };
41+
};
42+
1843
export const getThisAccountInfo = async (ctx: Koa.Context) => {
1944
const { title, owner } = ctx.query;
2045
const account = await accountService.getAccountByTitleAndOwner(title, owner);
@@ -31,4 +56,11 @@ export const postAccountUser = async (ctx: Koa.Context) => {
3156
ctx.body = { message: 'success' };
3257
};
3358

34-
export default { get, getThisAccountInfo, postAccountUser };
59+
export default {
60+
get,
61+
postAccount,
62+
putAccount,
63+
deleteAccount,
64+
getThisAccountInfo,
65+
postAccountUser,
66+
};

be/src/controllers/mms/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Context } from 'koa';
2+
import { postMms } from 'services/mms';
3+
4+
const post = async (ctx: Context) => {
5+
const { accountObjId, mmsObj, client } = ctx.request.body;
6+
try {
7+
const newMms = await postMms(accountObjId, mmsObj, client);
8+
ctx.status = 200;
9+
ctx.body = newMms;
10+
} catch (e) {
11+
ctx.body = { success: false, message: e };
12+
}
13+
};
14+
15+
export default { post };

be/src/controllers/user/index.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
1-
import Koa from 'koa';
1+
import { Context } from 'koa';
22
import * as userService from 'services/user';
33

4-
export const titleByAccountId = async (ctx: Koa.Context) => {
4+
export const titleByAccountId = async (ctx: Context) => {
55
const { accountId } = ctx.query;
66
const title = await userService.titleByAccountId(accountId);
77
ctx.status = 200;
88
ctx.response.body = title;
99
};
1010

11+
export const getUserList = async (ctx: Context) => {
12+
const userList = await userService.getUserList();
13+
ctx.status = 200;
14+
ctx.body = userList;
15+
};
16+
17+
export const getUserByAccessToken = async (ctx: Context) => {
18+
ctx.status = 200;
19+
ctx.body = ctx.request.body.user;
20+
};
21+
export const getInvitation = async (ctx: Context) => {
22+
const { user } = ctx.request.body;
23+
const accounts = await userService.getInvitation(user);
24+
const invitations = accounts.map((account: any, idx) => ({
25+
accountObjId: account._id,
26+
title: account.title,
27+
ownerName: account.ownerName,
28+
host: user.invitations[idx].host,
29+
}));
30+
ctx.body = invitations;
31+
};
32+
1133
export default titleByAccountId;

be/src/libs/error.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ export const invalidAccessError = {
1818
message: '해당 가계부에 접근 권한이 없습니다',
1919
};
2020

21+
export const updateUnclassifiedMethod = {
22+
status: 200,
23+
error: '수정할 수 없는 항목 입니다',
24+
success: false,
25+
};
26+
27+
export const UserHasNoAccount = {
28+
status: 400,
29+
message: 'user가 가지고 있는 account가 없습니다.',
30+
};
2131
export const invalidCategory = {
2232
status: 403,
2333
message: '해당 카테고리에 접근 할 수 없습니다',
@@ -29,18 +39,12 @@ export const removeUnclassifiedMethod = {
2939
success: false,
3040
};
3141

32-
export const updateUnclassifiedMethod = {
33-
status: 200,
34-
error: '수정할 수 없는 항목 입니다',
35-
success: false,
36-
};
37-
3842
export const invaildMethod = {
3943
status: 400,
4044
message: '잘못된 자원으로 접근하였습니다',
4145
};
4246

43-
export const UserHasNoAccount = {
47+
export const accountNoChange = {
4448
status: 400,
45-
message: 'user가 가지고 있는 account가 없습니다.',
49+
message: 'account Update 중 에러가 발생했습니다.',
4650
};

be/src/middlewares/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import {
66
invalidAccessError,
77
invalidCategory,
88
accountHasNoUserError,
9+
updateUnclassifiedMethod,
910
} from 'libs/error';
1011
import { UserModel } from 'models/user';
1112
import { CategoryModel, categoryType } from 'models/category';
12-
1313
import { AccountModel } from 'models/account';
1414

1515
interface IDecodedData {
@@ -77,3 +77,13 @@ export const isUnclassifide = async (
7777
}
7878
await next();
7979
};
80+
81+
export const titleIsUnclassified = async (
82+
ctx: Koa.Context,
83+
next: () => Promise<any>,
84+
) => {
85+
const { title } = ctx.request.body;
86+
if (!title || title.trim() === '' || title.trim() === '미분류')
87+
throw updateUnclassifiedMethod;
88+
await next();
89+
};

be/src/models/account/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface IAccount {
2020
methods?: string[];
2121
ownerName?: string;
2222
users: Types.DocumentArray<IUserDocument>;
23+
imageUrl?: String;
2324
}
2425

2526
export interface AccountDocument extends Document {
@@ -29,6 +30,7 @@ export interface AccountDocument extends Document {
2930
methods?: [String];
3031
ownerName?: string;
3132
users: Types.DocumentArray<IUserDocument>;
33+
imageUrl?: String;
3234
}
3335

3436
export interface IAccountDocument extends IAccount, Document {}
@@ -79,17 +81,18 @@ export const AccountSchema = new Schema({
7981
],
8082
ownerName: String,
8183
users: [UserSchema],
84+
imageUrl: String,
8285
});
8386

8487
AccountSchema.statics.findByPkAndPushTransaction = findByPkAndPushTransaction;
8588
AccountSchema.statics.findByPkAndGetTransCategory = findByPkAndGetTransCategory;
8689
AccountSchema.statics.findByTitleAndOwner = findByTitleAndOwner;
8790
AccountSchema.statics.findAllTransactionExceptDeleted = findAllTransactionExceptDeleted;
91+
AccountSchema.statics.findAccountByUserId = findAccountByUserId;
92+
AccountSchema.statics.findByPkAndPushUser = findByPkAndPushUser;
8893
AccountSchema.statics.findUnclassifiedCategory = findUnclassifiedCategory;
8994
AccountSchema.statics.findUnclassifiedMethod = findUnclassifiedMethod;
9095

91-
AccountSchema.statics.findAccountByUserId = findAccountByUserId;
92-
AccountSchema.statics.findByPkAndPushUser = findByPkAndPushUser;
9396
export const AccountModel = model<IAccountDocument, IAccountModel>(
9497
'accounts',
9598
AccountSchema,

be/src/models/account/static.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,34 +93,34 @@ export async function findByTitleAndOwner(
9393
) {
9494
if (!title || !owner) throw new NotVaildException();
9595

96-
return this.findOne({ title, owner }, { _id: true }).exec();
96+
return this.findOne({ title, ownerName: owner }, { _id: true }).exec();
9797
}
9898

99-
export async function findUnclassifiedCategory(
99+
export async function findUnclassifiedMethod(
100100
this: IAccountModel,
101101
accountObjId: string,
102102
) {
103-
const res: any = await this.findById(accountObjId, { categories: true })
103+
const res: any = await this.findById(accountObjId, { methods: true })
104104
.populate({
105-
path: 'categories',
106-
match: { type: categoryType.UNCLASSIFIED },
105+
path: 'methods',
106+
match: { title: '미분류' },
107107
select: '_id',
108108
})
109109
.exec();
110-
111-
return res.categories[0]._id;
110+
return res.methods[0]._id;
112111
}
113112

114-
export async function findUnclassifiedMethod(
113+
export async function findUnclassifiedCategory(
115114
this: IAccountModel,
116115
accountObjId: string,
117116
) {
118-
const res: any = await this.findById(accountObjId, { methods: true })
117+
const res: any = await this.findById(accountObjId, { categories: true })
119118
.populate({
120-
path: 'methods',
121-
match: { title: '미분류' },
119+
path: 'categories',
120+
match: { type: categoryType.UNCLASSIFIED },
122121
select: '_id',
123122
})
124123
.exec();
125-
return res.methods[0]._id;
124+
125+
return res.categories[0]._id;
126126
}

be/src/models/user/index.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Schema, model, Document } from 'mongoose';
1+
import { Schema, model, Document, Types } from 'mongoose';
22

33
export const UserSchema = new Schema({
44
timezone: {
@@ -16,17 +16,24 @@ export const UserSchema = new Schema({
1616
id: {
1717
type: String,
1818
},
19-
password: {
20-
type: String,
21-
},
22-
salt: {
23-
type: String,
24-
},
2519
profileUrl: {
2620
type: String,
2721
},
22+
invitations: [
23+
{
24+
accounts: {
25+
type: Types.ObjectId,
26+
ref: 'accounts',
27+
},
28+
host: String,
29+
},
30+
],
2831
});
2932

33+
export interface IInvitation {
34+
host: string;
35+
accounts: string;
36+
}
3037
export interface IUserDocument extends Document {
3138
timezone?: String;
3239
startOfWeek?: String;
@@ -35,6 +42,7 @@ export interface IUserDocument extends Document {
3542
salt?: String;
3643
nickname: String;
3744
profileUrl?: String;
45+
invitations?: Array<IInvitation>;
3846
}
3947

4048
export const UserModel = model<IUserDocument>('users', UserSchema);

be/src/routers/api/account/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ const router = new Router();
55

66
router.get('/info', accountController.getThisAccountInfo);
77
router.get('/', accountController.get);
8+
router.post('/', accountController.postAccount);
9+
router.put('/', accountController.putAccount);
10+
router.del('/', accountController.deleteAccount);
811
router.post('/user', accountController.postAccountUser);
912

1013
export default router;

be/src/routers/api/category/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import Router from 'koa-router';
22
import koaCompose from 'koa-compose';
33
import categoryController from 'controllers/category';
4-
import { isUnclassifide } from 'middlewares';
4+
import { isUnclassifide, titleIsUnclassified } from 'middlewares';
55

66
const router = new Router();
77

88
router.get('/statistics', categoryController.getStatisticsInfo);
99

1010
router.get('/', categoryController.get);
11-
router.post('/', categoryController.post);
12-
router.put('/', categoryController.put);
11+
router.post('/', koaCompose([titleIsUnclassified, categoryController.post]));
12+
router.put('/', koaCompose([titleIsUnclassified, categoryController.put]));
1313
router.delete(
1414
'/:category',
1515
koaCompose([isUnclassifide, categoryController.deleteCategory]),

0 commit comments

Comments
 (0)