Skip to content

Commit

Permalink
Merge pull request #129 from kookmin-sw/dev
Browse files Browse the repository at this point in the history
to merge master
  • Loading branch information
0__h0__ authored May 27, 2022
2 parents c72e2b0 + a1c47d3 commit 5988a99
Show file tree
Hide file tree
Showing 16 changed files with 213 additions and 66 deletions.
2 changes: 1 addition & 1 deletion application/icare/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function App() {
screenOptions={{
headerShown: false
}}>
<Stack.Screen name="Main" component={MainScreen} />
{/* <Stack.Screen name="Main" component={MainScreen} /> */}
<Stack.Screen name="Auth" component={AuthScreen} />
<Stack.Screen name="BSMain" component={BSMainScreen} />
<Stack.Screen name="Invitation" component={InvitationScreen} />
Expand Down
5 changes: 2 additions & 3 deletions application/icare/src/pages/BabyDiary/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ const BabyDiary: FC = (props) => {
]

useEffect(() => {
console.log(props.route.params)
if(props.route.params.dateString)
setDate(props.route.params.dateString)
if(props.route.params.day.dateString)
setDate(props.route.params.day.dateString)
else {
var today = new Date()
const year = today.getFullYear()
Expand Down
1 change: 0 additions & 1 deletion backend/src/controllers/alarm.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const upload = multer({
})

const sendAlarm = async (req:Request, res:Response, next:NextFunction) => {

const alarmCode: string = req.body.alarmCode
const alarmText: string = req.body.alarmText

Expand Down
11 changes: 7 additions & 4 deletions backend/src/controllers/bs.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,21 @@ const inputBSInfo = async (req:Request, res:Response, next:NextFunction) => {
.then((result) => {
res.status(201).json(result);
});
}
}


}

const getBSInfo = async (req:Request, res:Response, next:NextFunction) => {

// req.params.userId -> string이라 number로 변환
let returnData = {}

const bsId: number = +req.params.bsId;
const bs = await BabySitter.findOne({bsId: bsId});
const bs = await BabySitter.getBsInfomation(bsId);

console.log(bs.user)
if (bs) {
// returnData['bs'] = bs.Babysitter

res.status(200).json({bs})
}
else {
Expand Down
6 changes: 4 additions & 2 deletions backend/src/controllers/mapping.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const findParentList = async (req:Request, res: Response, next: NextFunction) =>
try{
const bsId : number = +req.params.bsId;

await BabySitter.findById(bsId)
// await BabySitter.findById(bsId)
const result = await Mapping.findMappingParentList(bsId);

const returnData = []
Expand All @@ -17,7 +17,9 @@ const findParentList = async (req:Request, res: Response, next: NextFunction) =>

result.map((value: any, index: number) => {
console.log(typeof(value))
returnData.push(value.parent)
if(value.status == "1"){
returnData.push(value)
}
})

res.status(200).json(returnData)
Expand Down
5 changes: 4 additions & 1 deletion backend/src/controllers/multer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ const upload = multer({
contentType: multerS3.AUTO_CONTENT_TYPE,
acl: 'public-read',

key: function (reqest, file, cb) {

key: function (req, file, cb) {


// console.log(req)
cb(null, `workdiary/${Date.now()}_${file.originalname}`)
},
Expand Down
98 changes: 79 additions & 19 deletions backend/src/controllers/parent.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Parent } from '../entity/Parent';
import { Mapping } from "../entity/Mapping";
import { WorkDiary } from "../entity/WorkDiary";
import { WorkDiaryImg } from "../entity/WorkDiaryImg";
import { Alarm } from "../entity/Alarm";

const getParentInfo = async (req: Request, res: Response, next: NextFunction) => {
const parent_id: number = +req.params.parentId;
Expand Down Expand Up @@ -87,6 +88,9 @@ const getMainPage = async (req: Request, res: Response, next: NextFunction) => {
const parent_id: number = +req.params.parentId;

const existMappingList = await Mapping.findMappingList(parent_id);

const parentInfo = await Parent.getParentEmail(parent_id);
const parentEmail: string = parentInfo.user['email']

let mapping_info = [];
let request_info = [];
Expand Down Expand Up @@ -116,20 +120,17 @@ const getMainPage = async (req: Request, res: Response, next: NextFunction) => {
else if (mapping_info.length === 0 && request_info.length !== 0) {
return res.status(200).json({
message: "보모의 매핑 요청 리스트",
request_info
})
} // 둘 다 없는 경우
else {
return res.status(404).json({
message: "매핑 및 요청 정보 없음"
request_info,
inviteEmail: parentEmail
})
}
}
// 존재하지 않는 parentId로 요청 보낸 경우
// 매핑 정보가 없는 경우
else {
return res.status(400).json({
message: "Invalid parentId"
});
return res.status(200).json({
request_info: [],
inviteEmail: parentEmail
})
}


Expand Down Expand Up @@ -187,10 +188,11 @@ const rejectMapping = async (req: Request, res: Response, next: NextFunction) =>

const getDailyDiary = async (req: Request, res: Response, next: NextFunction) => {
const mappingId: number = +req.params.mappingId;

// mappingId를 이용하여 금일 퇴근일지 가져오기
const daily_work_diary = await WorkDiary.findDiarybyMappingId(mappingId);

const daily_alarm_list = await Alarm.findAlarmbyMappingId(mappingId);

if (daily_work_diary === undefined) {
return res.status(404).json({
message: "금일 작성된 퇴근일지가 존재하지 않습니다."
Expand All @@ -202,7 +204,9 @@ const getDailyDiary = async (req: Request, res: Response, next: NextFunction) =>
.then((result) => {
return res.status(200).json({
dailyDiary: daily_work_diary,
dailyImageList: result

dailyImageList: result,
dailyAlarmList: daily_alarm_list
})
})
.catch((err) => {
Expand All @@ -217,25 +221,81 @@ const getCalendarDiary = async (req: Request, res: Response, next: NextFunction)

// mappingId, 날짜를 이용하여 특정 날짜의 퇴근일지 가져오기
const calendar_work_diary = await WorkDiary.findCalendarDiary(mappingId, date);
const calendar_alarm_list = await Alarm.findCalendarAlarmList(mappingId, date);

if (calendar_work_diary === undefined) {
return res.status(404).json({
message: "해당 날짜에 작성된 퇴근일지가 존재하지 않습니다."
// 알람도 없고 퇴근 일지도 없는 경우
if (calendar_work_diary === undefined && calendar_alarm_list.length === 0) {
return res.status(200).json({
CalendarDiary: {
issue: ""
},
CalendarImageList : [],
CalendarAlarmList: []
})
}
else {

} // 알람은 없고 퇴근 일지만 있는 경우
else if (calendar_work_diary !== undefined && calendar_alarm_list === []) {
// 가져온 퇴근일지 ID, 날짜를 이용하여 특정 날짜에 작성된 퇴근일지 이미지 리스트 가져오기
await WorkDiaryImg.findImgUsingIdAndDate(calendar_work_diary.diaryId, date)
.then((result) => {
return res.status(200).json({
CalendarDiary: calendar_work_diary,
CalendarImageList: result
CalendarImageList: result,
CalendarAlarmList: []
})
})
.catch((err) => {
res.status(400).json(err);
})
} // 알람은 있는데 퇴근 일지는 없는 경우
else if (calendar_work_diary === undefined && calendar_alarm_list !== []) {
return res.status(200).json({
CalendarAlarmList: calendar_alarm_list,
CalendarDiary: {issue: ""},
CalendarImageList: []
})

} // 알람, 퇴근일지 전부 있는 경우
else if (calendar_work_diary !== undefined && calendar_alarm_list !== []) {
await WorkDiaryImg.findImgUsingIdAndDate(calendar_work_diary.diaryId, date)
.then((result) => {
return res.status(200).json({
CalendarDiary: calendar_work_diary,
CalendarImageList: result,
CalendarAlarmList: calendar_alarm_list
})
})
.catch((err) => {
res.status(400).json(err);
})
}

}

const getSensorInfo = async (req: Request, res: Response, next: NextFunction) => {
const mappingInfo = await Mapping.find({mappingId: 6})

return res.status(200).json({
alert: mappingInfo[0].alert
})
}

const updateSensorInfo = async (req: Request, res: Response, next: NextFunction) => {
await Mapping.update({mappingId: 6}, {alert: false})
.then((result) => {
res.status(200).json({
message: "success"
})
})
}

const updateSensorAlert = async (req: Request, res: Response, next: NextFunction) => {
await Mapping.update({mappingId: 6}, {alert: true})
.then((result) => {
res.status(200).json({
message: "success"
})
})
}

export default {getParentInfo, editParentInfo, createParentInfo, getMainPage, acceptMapping, rejectMapping, getDailyDiary, getCalendarDiary};
export default {getParentInfo, editParentInfo, createParentInfo, getMainPage, acceptMapping, rejectMapping, getDailyDiary, getCalendarDiary, getSensorInfo, updateSensorInfo, updateSensorAlert};
84 changes: 61 additions & 23 deletions backend/src/controllers/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Request, Response, NextFunction } from "express";
import { User } from '../entity/User';
import bcrypt from "bcrypt";
import * as jwt from 'jsonwebtoken';
import { Parent } from "../entity/Parent";
import { BabySitter } from "../entity/BabySitter";

const signup = async (req: Request, res: Response, next: NextFunction) => {
const saltRound = 10;
Expand Down Expand Up @@ -51,7 +53,6 @@ const signup = async (req: Request, res: Response, next: NextFunction) => {

const login = async (req: Request, res: Response, next: NextFunction) => {
const {email, password} = req.body;

const user = await User.find({
email: email
})
Expand All @@ -62,31 +63,68 @@ const login = async (req: Request, res: Response, next: NextFunction) => {
})
}
else {
const check = await bcrypt.compare(password, user[0].password);

if(check) { // 패스워드 일치 시 토큰 발행
const token = jwt.sign({
type: 'JWT',
email: email,
}, process.env.SECRET_KEY, {
expiresIn: '24h', // 만료시간 24h
issuer: 'icare',
}
);
if (user[0].code === 1) {
const parent = await Parent.find({user: user[0]})

res.status(200).json({
success: true,
message: "토큰 발행 완료",
token: token,
userInfo: user
});

}
else {
res.status(400).json({
message: "비밀번호가 일치하지 않습니다."
})
const check = await bcrypt.compare(password, user[0].password);

if(check) { // 패스워드 일치 시 토큰 발행
const token = jwt.sign({
type: 'JWT',
email: email,
}, process.env.SECRET_KEY, {
expiresIn: '24h', // 만료시간 24h
issuer: 'icare',
}
);

res.status(200).json({
success: true,
message: "토큰 발행 완료",
token: token,
userInfo: user,
parentId: parent[0].parentId
});

}
else {
res.status(400).json({
message: "비밀번호가 일치하지 않습니다."
})
}
}
else if (user[0].code === 2) {
const sitter = await BabySitter.find({user: user[0]});

const check = await bcrypt.compare(password, user[0].password);

if(check) { // 패스워드 일치 시 토큰 발행
const token = jwt.sign({
type: 'JWT',
email: email,
}, process.env.SECRET_KEY, {
expiresIn: '24h', // 만료시간 24h
issuer: 'icare',
}
);

res.status(200).json({
success: true,
message: "토큰 발행 완료",
token: token,
userInfo: user,
sitterId: sitter[0].bsId
});

}
else {
res.status(400).json({
message: "비밀번호가 일치하지 않습니다."
})
}
}

}
};

Expand Down
5 changes: 1 addition & 4 deletions backend/src/controllers/workdiary.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ const uploadImg = upload.upload.array('img');

const writeWorkdiary = async (req:Request, res:Response, next:NextFunction) => {
console.log(req.body)
// console.log(req)
// console.log("-------------------")
// console.log((req as MulterRequest))



uploadImg(req,res,async (err) => {
if(err){
Expand Down
22 changes: 22 additions & 0 deletions backend/src/entity/Alarm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,27 @@ export class Alarm extends BaseEntity {
@JoinColumn({name: "mappingId"})
mapping: Mapping

// 당일 작성된 알람 이미지 리스트 가져오기
static async findAlarmbyMappingId(mappingId: number) {

const date = new Date();
let year: number = date.getFullYear();
let month: string = ("0" + (1 + date.getMonth())).slice(-2);
let day: string = ("0" + date.getDate()).slice(-2);

return await this.createQueryBuilder("alarm")
.where("alarm.mappingId = :mappingId", {mappingId: mappingId})
.andWhere("DATE_FORMAT(alarm.createdAt, '%Y-%m-%d') = :date", {date: year + "-" + month + "-" + day})
.getMany();
}

// 알람 테이블에서 클릭한 날짜에 저장된 이미지 가져오기
static async findCalendarAlarmList(mappingId: number, date: string) {

return await this.createQueryBuilder("alarm")
.where("alarm.mappingId = :mappingId", {mappingId: mappingId})
.andWhere("DATE_FORMAT(alarm.createdAt, '%Y-%m-%d') = :date", {date: date})
.getMany();
}

}
Loading

0 comments on commit 5988a99

Please sign in to comment.