Skip to content

Commit

Permalink
Merge pull request #490 from connect-foundation/Develop
Browse files Browse the repository at this point in the history
PR Develop to master : releaseCode:: End game
  • Loading branch information
teihong93 authored Dec 20, 2019
2 parents f48eb46 + a5b68af commit 1699874
Show file tree
Hide file tree
Showing 329 changed files with 3,899 additions and 3,983 deletions.
10 changes: 7 additions & 3 deletions backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,14 @@ AUTH_PROD_TOKEN_AUDIENCE=
#######################################################################################################################
# redis
REDIS_DEV_CONTAINER_NAME=redis_dev
REDIS_DEV_PORT=6379
REDIS_DEV_PORT=6380
REDIS_DEV_HOST=127.0.0.1

REDIS_PROD_CONTAINER_NAME=redis_dev
REDIS_TEST_CONTAINER_NAME=redis_test
REDIS_TEST_PORT=6381
REDIS_TEST_HOST=127.0.0.1

REDIS_PROD_CONTAINER_NAME=redis
REDIS_PROD_PORT=6379
REDIS_PROD_HOST=127.0.0.1
REDIS_PROD_HOST=redis
#######################################################################################################################
66 changes: 66 additions & 0 deletions backend/DB/dummy/RandomGuestName/Adjective.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const Adjectives = [
"춤추는",
"멋있는",
"차가운",
"뜨거운",
"호기심이 많은",
"귀여운",
"울부짖는",
"궁금한게 많은",
"노래하는",
"랩하는",
"화사한",
"맵시있는",
"요리하는",
"재미있는",
"큰 눈의",
"착한",
"정직한",
"조용한",
"즐거운",
"졸고있는",
"기쁜",
"벅찬",
"포근한",
"흐뭇한",
"상쾌한",
"시원한",
"반가운",
"후련한",
"살맛 나는",
"신바람 나는",
"아늑한",
"흥분되는",
"온화한",
"느긋한",
"끝내주는",
"괜찮은",
"쌈박한",
"정다운",
"그리운",
"자유로운",
"따사로운",
"감미로운",
"황홀한",
"상큼한",
"개념있는",
"지성적인",
"자상한",
"아리따운",
"여유있는",
"감정이 풍부한",
"활기찬",
"힘찬",
"생생한",
"의기 양양한",
"든든한",
"격렬한",
"당당한",
"팔팔한",
"엄청난",
"자신만만한",
"패기만만한",
"충만한",
];

export default Adjectives;
3 changes: 3 additions & 0 deletions backend/DB/dummy/RandomGuestName/Animals.js

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

12 changes: 12 additions & 0 deletions backend/DB/dummy/RandomGuestName/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import faker from "faker";
import Adjectives from "./Adjective.js";
import Animals from "./Animals.js";

function getRandomGuestName() {
const adjective = faker.random.arrayElement(Adjectives);
const animal = faker.random.arrayElement(Animals);

return `${adjective} ${animal}`;
}

export default getRandomGuestName;
5 changes: 5 additions & 0 deletions backend/DB/logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import getLogger from "../libs/logger.js";

const logger = getLogger("mySQL_Query");

export default logger;
7 changes: 2 additions & 5 deletions backend/DB/queries/candidate.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import Sequelize from "sequelize";
import models from "../models";

const Sequelize = require("sequelize");

const Op = Sequelize.Op;

export async function getCandidatesByPollId(pollIdList) {
const result = await models.Candidate.findAll({
return models.Candidate.findAll({
where: {
PollId: {
[Op.or]: pollIdList,
},
},
});

return result;
}
114 changes: 15 additions & 99 deletions backend/DB/queries/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,141 +16,57 @@ export async function createEvent({
return models.Event.findOrCreate({
where: {eventCode},
defaults: {
eventName,
HostId,
moderationOption,
replyOption,
startAt,
endAt,
HostId,
eventName,
},
});
}

export async function updateEventById(
export async function updateEventById({
id,
{eventName, moderationOption, replyOption, startAt, endAt}
) {
eventName,
moderationOption,
replyOption,
startAt,
endAt,
}) {
return models.Event.update(
{eventName, moderationOption, replyOption, startAt, endAt},
{where: {id}}
{where: {id}},
);
}

export async function getEventsByHostId(hostId) {
const events = await models.Event.findAll({
return models.Event.findAll({
where: {HostId: hostId},
});

return events;
}

export async function getEventIdByEventCode(eventCode) {
const event = await models.Event.findOne({
export async function getEventByEventCode(eventCode) {
return models.Event.findOne({
where: {
eventCode,
},
attributes: ["id"],
});

return event;
}

export async function getEventById(EventId) {
const event = await models.Event.findOne({
return models.Event.findOne({
where: {
id: EventId,
},
});

return event;
}

export async function getEventOptionByEventId(id) {
const event = await models.Event.findOne({
return models.Event.findOne({
where: {
id,
},
attributes: ["moderationOption", "replyOption"],
});

return event;
}

export async function getQuestionLikeCount(EventId = 2, limit, offset) {
return models.Question.findAll({
attributes: ["id", [models.sequelize.fn("count", "*"), "likeCount"]],
where: {EventId, QuestionId: null},
include: [
{
model: models.Like,
attributes: [],
},
],
group: "id",
offset,
limit,
});
}

export async function getQuestionsByEventCodeAndGuestId(
eventCode,
guestId,
limit = 70,
offset
) {
// const event = await models.Event.findOne({where: {eventCode}});
// const EventId = event.dataValues.id
const EventId = 2;

return models.Question.findAll({
where: {EventId, QuestionId: null},
include: [
{
model: models.Like,
},
{
model: models.Emoji,
},
{
model: models.Guest,
},
],
offset,
limit,
});
}

export async function raw_getQuestionsByEventCodeAndGuestId(
eventCode,
guestId,
limit = 100,
offset = 0
) {
// const event = await models.Event.findOne({where: {eventCode}});
// const EventId = event.dataValues.id
const EventId = 2;

const query = `
select *, Emojis.name, Emojis.GuestId
from Questions
inner join Emojis on Questions.id = Emojis.QuestionId
where EventId = :EventId and Questions.QuestionId is null
-- order by Emojis.QuestionId DESC
-- limit :limit offset :offset
-- group by Emojis.QuestionId
`;
// console.log(event.dataValues.id)
const [questions] = await models.sequelize.query(query, {
replacements: {
EventId,
limit,
offset,
type: Sequelize.QueryTypes.SELECT,
raw: true,
},
});

return questions;
}
26 changes: 12 additions & 14 deletions backend/DB/queries/guest.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import uuidv1 from "uuid/v1";
import models from "../models";
import getRandomGuestName from "../dummy/RandomGuestName";

const Guest = models.Guest;

async function findGuestBySid(guestSid) {
const guest = await Guest.findOne({where: {guestSid}});
const result = guest ? guest.dataValues : false;
async function getGuestByGuestSid(guestSid) {
return Guest.findOne({where: {guestSid}});
}

return result;
async function isExistGuest(guestSid) {
return !!(await getGuestByGuestSid(guestSid));
}

async function createGuest(name, eventId) {
async function createGuest(eventId) {
const guest = await Guest.create({
name,
name: getRandomGuestName(),
EventId: eventId,
guestSid: uuidv1(),
isAnonymous: 1,
});

const result = guest ? guest.dataValues : false;

return result;
return guest.get({plain: true});
}

async function getGuestById(id) {
Expand All @@ -30,10 +30,7 @@ async function getGuestById(id) {
}

async function updateGuestById({id, name, isAnonymous, company, email}) {
return Guest.update(
{name, company, isAnonymous, email},
{where: {id}},
);
return Guest.update({name, company, isAnonymous, email}, {where: {id}});
}

async function getGuestByEventId(EventId) {
Expand All @@ -45,5 +42,6 @@ export {
getGuestById,
updateGuestById,
getGuestByEventId,
findGuestBySid,
isExistGuest,
getGuestByGuestSid
};
2 changes: 1 addition & 1 deletion backend/DB/queries/hashtag.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const Hashtag = models.Hashtag;
export async function createHashtag({name, EventId}) {
return Hashtag.create(
{name, EventId},
{default: {updateAt: new Date(), createAt: new Date()}}
{default: {updateAt: new Date(), createAt: new Date()}},
);
}

Expand Down
19 changes: 8 additions & 11 deletions backend/DB/queries/host.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import models from "../models";

async function findHostByAuthId(oAuthid) {
const host = await models.Host.findOne({where: {oauthId: oAuthid}});
const result = host ? host.dataValues : false;
// todo: 더 좋은 이름
export async function findHostByAuthId(oauthId) {
const host = await models.Host.findOne({where: {oauthId}});

return result;
return host ? host.dataValues : false;
}

async function createHost(oAuthid, name, image, email) {
export async function createHost(oauthId, name, image, email) {
const host = await models.Host.create({
oauthId: oAuthid,
oauthId,
name,
email,
image,
emailFeedBack: 0,
emailFeedBack: false,
});
const result = host ? host.dataValues : false;

return result;
return host ? host.dataValues : false;
}

export {createHost, findHostByAuthId};
Loading

0 comments on commit 1699874

Please sign in to comment.