Skip to content

Commit

Permalink
Upgrade Sequelize
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffreyATW committed Feb 13, 2023
1 parent 3ae6b1f commit daa2c41
Show file tree
Hide file tree
Showing 11 changed files with 256 additions and 285 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"common-password": "^0.1.2",
"compression": "^1.6.1",
"connect-flash": "^0.1.1",
"connect-session-sequelize": "^4.1.0",
"connect-session-sequelize": "^7.1.5",
"cookie-parser": "^1.4.3",
"core-js": "^2.5.4",
"cors": "^2.8.3",
Expand Down Expand Up @@ -78,8 +78,8 @@
"robust-websocket": "^0.2.1",
"rotating-file-stream": "^1.2.1",
"sendgrid": "^5.2.3",
"sequelize": "^4.38.1",
"sequelize-cli": "^4.1.0",
"sequelize": "^6.28.0",
"sequelize-cli": "^6.6.0",
"serialize-javascript": "^1.5.0",
"source-map-support": "^0.5.9",
"sqlite3": "^5.0.11",
Expand Down
6 changes: 3 additions & 3 deletions src/api/team/decisions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default () => {
const opts = { where: { team_id: req.team.id } };
const days = parseInt(req.query.days, 10);
if (!Number.isNaN(days)) {
opts.where.created_at = {
opts.where.createdAt = {
[DataTypes.Op.gt]: dayjs().subtract(days, 'days').toDate()
};
}
Expand All @@ -43,7 +43,7 @@ export default () => {
const daysAgo = parseInt(req.body.daysAgo, 10);
let MaybeScopedDecision = Decision;
if (daysAgo > 0) {
destroyOpts.where.created_at = {
destroyOpts.where.createdAt = {
[DataTypes.Op.gt]: dayjs().subtract(daysAgo, 'days').subtract(12, 'hours').toDate(),
[DataTypes.Op.lt]: dayjs().subtract(daysAgo, 'days').add(12, 'hours').toDate(),
};
Expand All @@ -60,7 +60,7 @@ export default () => {
team_id: req.team.id
};
if (daysAgo > 0) {
createOpts.created_at = dayjs().subtract(daysAgo, 'days').toDate();
createOpts.createdAt = dayjs().subtract(daysAgo, 'days').toDate();
}
const obj = await Decision.create(createOpts);

Expand Down
2 changes: 1 addition & 1 deletion src/api/team/restaurants.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default () => {
checkTeamRole(),
async (req, res, next) => {
try {
const r = await Restaurant.findById(parseInt(req.params.id, 10));
const r = await Restaurant.findByPk(parseInt(req.params.id, 10));

if (r === null || r.team_id !== req.team.id) {
notFound(res);
Expand Down
6 changes: 3 additions & 3 deletions src/api/tests/decisions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('api/team/decisions', () => {
it('looks for decisions within past 5 days', () => {
expect(findAllSpy.calledWith({
where: {
created_at: {
createdAt: {
gt: match.date,
},
team_id: 77
Expand Down Expand Up @@ -195,7 +195,7 @@ describe('api/team/decisions', () => {
it('deletes any prior decisions', () => {
expect(destroySpy.calledWith({
where: {
created_at: {
createdAt: {
lt: match.date,
gt: match.date,
},
Expand All @@ -206,7 +206,7 @@ describe('api/team/decisions', () => {

it('creates new decision', () => {
expect(createSpy.calledWith({
created_at: match.date,
createdAt: match.date,
restaurant_id: 1,
team_id: 77
})).to.be.true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const DecisionPosted = ({
</button>
);
if (loggedIn) {
if (dayjs().subtract(12, 'hours').isAfter(decision.created_at)) {
if (dayjs().subtract(12, 'hours').isAfter(decision.createdAt)) {
return (
<span>
<b>{user}</b>
Expand Down
2 changes: 1 addition & 1 deletion src/models/Decision.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const Decision = sequelize.define(
scopes: {
fromToday: () => ({
where: {
created_at: {
createdAt: {
[DataTypes.Op.gt]: dayjs().subtract(12, 'hours').toDate()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/models/Vote.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const Vote = sequelize.define(
scopes: {
fromToday: () => ({
where: {
created_at: {
createdAt: {
[DataTypes.Op.gt]: dayjs().subtract(12, 'hours').toDate()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Team.findAllForUser = (user) => Team.findAll({
});

// eslint-disable-next-line camelcase
Restaurant.findAllWithTagIds = ({ team_id }) => Team.findById(team_id).then((team) => Restaurant.findAll({
Restaurant.findAllWithTagIds = ({ team_id }) => Team.findByPk(team_id).then((team) => Restaurant.findAll({
attributes: {
include: [
[
Expand Down
6 changes: 3 additions & 3 deletions src/selectors/decisions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const getDecisionsByDay = createSelector(
[getDecisionIds, getDecisionEntities],
(decisionIds, decisionEntities) => decisionIds.reduce((acc, curr) => {
const decision = decisionEntities[curr];
const createdAt = dayjs(decision.created_at);
const createdAt = dayjs(decision.createdAt);
let comparisonDate = dayjs().subtract(12, 'hours');
for (let i = 0; i < 5; i += 1) {
if (createdAt.isAfter(comparisonDate)) {
Expand All @@ -38,7 +38,7 @@ export const getDecisionsByRestaurantId = createSelector(
getDecisionEntities,
(decisionIds, decisionEntities) => decisionIds.reduce((acc, curr) => {
const decision = decisionEntities[curr];
acc[decision.restaurant_id] = new Date(decision.created_at).toLocaleDateString();
acc[decision.restaurant_id] = new Date(decision.createdAt).toLocaleDateString();
return acc;
}, {}),
);
Expand All @@ -54,7 +54,7 @@ export const getDecision = createSelector(
}
const twelveHoursAgo = dayjs().subtract(12, 'hours');
for (let i = 0; i < decisionIds.length; i += 1) {
if (dayjs(decisionEntities[decisionIds[i]].created_at).isAfter(twelveHoursAgo)) {
if (dayjs(decisionEntities[decisionIds[i]].createdAt).isAfter(twelveHoursAgo)) {
return decisionEntities[decisionIds[i]];
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/selectors/tests/decisions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ describe('selectors/decisions', () => {
entities: {
decisions: {
1: {
created_at: dayjs(now),
createdAt: dayjs(now),
},
2: {
created_at: dayjs(now).subtract(23, 'hours'),
createdAt: dayjs(now).subtract(23, 'hours'),
},
3: {
created_at: dayjs(now).subtract(25, 'hours'),
createdAt: dayjs(now).subtract(25, 'hours'),
},
4: {
created_at: dayjs(now).subtract(48, 'hours'),
createdAt: dayjs(now).subtract(48, 'hours'),
},
},
},
Expand Down
Loading

0 comments on commit daa2c41

Please sign in to comment.