mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Merge branch 'master' into dependabot/npm_and_yarn/backend/eslint-import-resolver-typescript-3.6.1
This commit is contained in:
commit
8f3a178f1e
@ -7,7 +7,8 @@ module.exports = {
|
|||||||
'!**/node_modules/**',
|
'!**/node_modules/**',
|
||||||
'!**/test/**',
|
'!**/test/**',
|
||||||
'!**/build/**',
|
'!**/build/**',
|
||||||
'!**/src/**/?(*.)+(spec|test).ts?(x)'
|
'!**/src/**/?(*.)+(spec|test).ts?(x)',
|
||||||
|
'!**/src/db/migrations/**'
|
||||||
],
|
],
|
||||||
coverageThreshold: {
|
coverageThreshold: {
|
||||||
global: {
|
global: {
|
||||||
|
|||||||
68
backend/src/db/migrations/20231017141022-fix-event-dates.ts
Normal file
68
backend/src/db/migrations/20231017141022-fix-event-dates.ts
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
import { getDriver } from '../../db/neo4j'
|
||||||
|
|
||||||
|
export const description = `
|
||||||
|
Transform event start and end date of format 'YYYY-MM-DD HH:MM:SS' in CEST
|
||||||
|
to ISOString in UTC.
|
||||||
|
`
|
||||||
|
|
||||||
|
export async function up(next) {
|
||||||
|
const driver = getDriver()
|
||||||
|
const session = driver.session()
|
||||||
|
const transaction = session.beginTransaction()
|
||||||
|
|
||||||
|
try {
|
||||||
|
const events = await transaction.run(`
|
||||||
|
MATCH (event:Event)
|
||||||
|
WHERE NOT event.eventStart CONTAINS 'T'
|
||||||
|
RETURN event.id, event.eventStart, event.eventEnd
|
||||||
|
`)
|
||||||
|
for (const event of events.records) {
|
||||||
|
let [id, eventStart, eventEnd] = event
|
||||||
|
let date = new Date(eventStart)
|
||||||
|
date.setHours(date.getHours() - 1)
|
||||||
|
eventStart = date.toISOString()
|
||||||
|
if (eventEnd) {
|
||||||
|
date = new Date(eventEnd)
|
||||||
|
date.setHours(date.getHours() - 1)
|
||||||
|
eventEnd = date.toISOString()
|
||||||
|
}
|
||||||
|
await transaction.run(`
|
||||||
|
MATCH (e:Event { id: '${id}' })
|
||||||
|
SET e.eventStart = '${eventStart}'
|
||||||
|
SET (CASE WHEN exists(e.eventEnd) THEN e END).eventEnd = '${eventEnd}'
|
||||||
|
RETURN e
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
await transaction.commit()
|
||||||
|
next()
|
||||||
|
} catch (error) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log(error)
|
||||||
|
await transaction.rollback()
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('rolled back')
|
||||||
|
throw new Error(error)
|
||||||
|
} finally {
|
||||||
|
session.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(next) {
|
||||||
|
const driver = getDriver()
|
||||||
|
const session = driver.session()
|
||||||
|
const transaction = session.beginTransaction()
|
||||||
|
|
||||||
|
try {
|
||||||
|
// No sense in running this down
|
||||||
|
next()
|
||||||
|
} catch (error) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log(error)
|
||||||
|
await transaction.rollback()
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('rolled back')
|
||||||
|
throw new Error(error)
|
||||||
|
} finally {
|
||||||
|
session.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -34,6 +34,8 @@ const validateEventDate = (dateString) => {
|
|||||||
const date = new Date(dateString)
|
const date = new Date(dateString)
|
||||||
if (date.toString() === 'Invalid Date')
|
if (date.toString() === 'Invalid Date')
|
||||||
throw new UserInputError('Event start date must be a valid date!')
|
throw new UserInputError('Event start date must be a valid date!')
|
||||||
|
if (date.toISOString() !== dateString)
|
||||||
|
throw new UserInputError('Event start date must be in ISO format!')
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
if (date.getTime() < now.getTime()) {
|
if (date.getTime() < now.getTime()) {
|
||||||
throw new UserInputError('Event start date must be in the future!')
|
throw new UserInputError('Event start date must be in the future!')
|
||||||
@ -44,6 +46,8 @@ const validateEventEnd = (start, end) => {
|
|||||||
const endDate = new Date(end)
|
const endDate = new Date(end)
|
||||||
if (endDate.toString() === 'Invalid Date')
|
if (endDate.toString() === 'Invalid Date')
|
||||||
throw new UserInputError('Event end date must be a valid date!')
|
throw new UserInputError('Event end date must be a valid date!')
|
||||||
|
if (endDate.toISOString() !== end)
|
||||||
|
throw new UserInputError('Event end date must be in ISO format!')
|
||||||
const startDate = new Date(start)
|
const startDate = new Date(start)
|
||||||
if (endDate < startDate)
|
if (endDate < startDate)
|
||||||
throw new UserInputError('Event end date must be a after event start date!')
|
throw new UserInputError('Event end date must be a after event start date!')
|
||||||
|
|||||||
@ -374,6 +374,31 @@ describe('CreatePost', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('with event start in no ISO format', () => {
|
||||||
|
it('throws an error', async () => {
|
||||||
|
const now = new Date()
|
||||||
|
const eventStart = new Date(now.getFullYear(), now.getMonth() - 1).toISOString()
|
||||||
|
await expect(
|
||||||
|
mutate({
|
||||||
|
mutation: createPostMutation(),
|
||||||
|
variables: {
|
||||||
|
...variables,
|
||||||
|
postType: 'Event',
|
||||||
|
eventInput: {
|
||||||
|
eventStart: eventStart.split('T')[0],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
).resolves.toMatchObject({
|
||||||
|
errors: [
|
||||||
|
{
|
||||||
|
message: 'Event start date must be in ISO format!',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('with event start date in the past', () => {
|
describe('with event start date in the past', () => {
|
||||||
it('throws an error', async () => {
|
it('throws an error', async () => {
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
@ -423,6 +448,32 @@ describe('CreatePost', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('with valid start date and not ISO formated end date', () => {
|
||||||
|
it('throws an error', async () => {
|
||||||
|
const now = new Date()
|
||||||
|
const eventEnd = new Date(now.getFullYear(), now.getMonth() + 2).toISOString()
|
||||||
|
await expect(
|
||||||
|
mutate({
|
||||||
|
mutation: createPostMutation(),
|
||||||
|
variables: {
|
||||||
|
...variables,
|
||||||
|
postType: 'Event',
|
||||||
|
eventInput: {
|
||||||
|
eventStart: new Date(now.getFullYear(), now.getMonth() + 1).toISOString(),
|
||||||
|
eventEnd: eventEnd.split('T')[0],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
).resolves.toMatchObject({
|
||||||
|
errors: [
|
||||||
|
{
|
||||||
|
message: 'Event end date must be in ISO format!',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('with valid start date and end date before start date', () => {
|
describe('with valid start date and end date before start date', () => {
|
||||||
it('throws an error', async () => {
|
it('throws an error', async () => {
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
|
|||||||
@ -328,9 +328,9 @@ export default {
|
|||||||
eventInput() {
|
eventInput() {
|
||||||
if (this.createEvent) {
|
if (this.createEvent) {
|
||||||
return {
|
return {
|
||||||
eventStart: this.formData.eventStart,
|
eventStart: new Date(this.formData.eventStart).toISOString(),
|
||||||
eventVenue: this.formData.eventVenue,
|
eventVenue: this.formData.eventVenue,
|
||||||
eventEnd: this.formData.eventEnd,
|
eventEnd: this.formData.eventEnd ? new Date(this.formData.eventEnd).toISOString() : null,
|
||||||
eventIsOnline: this.formData.eventIsOnline,
|
eventIsOnline: this.formData.eventIsOnline,
|
||||||
eventLocationName: !this.formData.eventIsOnline ? this.formData.eventLocationName : null,
|
eventLocationName: !this.formData.eventIsOnline ? this.formData.eventLocationName : null,
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user