trim place's name and description + event's title - fix #189
This commit is contained in:
@@ -8,12 +8,12 @@ v-card.h-event.event.d-flex(itemscope itemtype="https://schema.org/Event")
|
|||||||
v-card-text.body.pt-0.pb-0
|
v-card-text.body.pt-0.pb-0
|
||||||
time.dt-start.subtitle-1(:datetime='event.start_datetime | unixFormat("YYYY-MM-DD HH:mm")' itemprop="startDate" :content="event.start_datetime | unixFormat('YYYY-MM-DDTHH:mm')") <v-icon v-text='mdiCalendar'></v-icon> {{ event | when }}
|
time.dt-start.subtitle-1(:datetime='event.start_datetime | unixFormat("YYYY-MM-DD HH:mm")' itemprop="startDate" :content="event.start_datetime | unixFormat('YYYY-MM-DDTHH:mm')") <v-icon v-text='mdiCalendar'></v-icon> {{ event | when }}
|
||||||
.d-none.dt-end(itemprop="endDate" :content="event.end_datetime | unixFormat('YYYY-MM-DDTHH:mm')") {{ event.end_datetime | unixFormat('YYYY-MM-DD HH:mm') }}
|
.d-none.dt-end(itemprop="endDate" :content="event.end_datetime | unixFormat('YYYY-MM-DDTHH:mm')") {{ event.end_datetime | unixFormat('YYYY-MM-DD HH:mm') }}
|
||||||
nuxt-link.place.d-block.p-location.pl-0(text color='primary' :to='`/place/${event.place.name}`' itemprop="location" itemscope itemtype="https://schema.org/Place") <v-icon v-text='mdiMapMarker'></v-icon> <span itemprop='name'>{{ event.place.name }}</span>
|
nuxt-link.place.d-block.p-location.pl-0(text color='primary' :to='`/place/${encodeURIComponent(event.place.name)}`' itemprop="location" itemscope itemtype="https://schema.org/Place") <v-icon v-text='mdiMapMarker'></v-icon> <span itemprop='name'>{{ event.place.name }}</span>
|
||||||
.d-none(itemprop='address') {{ event.place.address }}
|
.d-none(itemprop='address') {{ event.place.address }}
|
||||||
|
|
||||||
v-card-actions.pt-0.actions.justify-space-between
|
v-card-actions.pt-0.actions.justify-space-between
|
||||||
.tags
|
.tags
|
||||||
v-chip.ml-1.mt-1(v-for='tag in event.tags.slice(0, 6)' small :to='`/tag/${tag}`'
|
v-chip.ml-1.mt-1(v-for='tag in event.tags.slice(0, 6)' small :to='`/tag/${encodeURIComponent(tag)}`'
|
||||||
:key='tag' outlined color='primary') {{ tag }}
|
:key='tag' outlined color='primary') {{ tag }}
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ v-row
|
|||||||
hide-no-data
|
hide-no-data
|
||||||
@input.native='search'
|
@input.native='search'
|
||||||
persistent-hint
|
persistent-hint
|
||||||
|
:value='value'
|
||||||
:items="places"
|
:items="places"
|
||||||
item-text='name'
|
item-text='name'
|
||||||
@focus='search'
|
@focus='search'
|
||||||
@@ -83,13 +84,13 @@ export default {
|
|||||||
selectPlace (p) {
|
selectPlace (p) {
|
||||||
if (!p) { return }
|
if (!p) { return }
|
||||||
if (typeof p === 'object' && !p.create) {
|
if (typeof p === 'object' && !p.create) {
|
||||||
this.place.name = p.name.trim()
|
this.place.name = p.name
|
||||||
this.place.address = p.address
|
this.place.address = p.address
|
||||||
this.place.id = p.id
|
this.place.id = p.id
|
||||||
this.disableAddress = true
|
this.disableAddress = true
|
||||||
} else { // this is a new place
|
} else { // this is a new place
|
||||||
this.place.name = p.name || p
|
this.place.name = (p.name || p).trim()
|
||||||
const tmpPlace = this.place.name.trim().toLocaleLowerCase()
|
const tmpPlace = this.place.name.toLocaleLowerCase()
|
||||||
// search for a place with the same name
|
// search for a place with the same name
|
||||||
const place = this.places.find(p => !p.create && p.name.trim().toLocaleLowerCase() === tmpPlace)
|
const place = this.places.find(p => !p.create && p.name.trim().toLocaleLowerCase() === tmpPlace)
|
||||||
if (place) {
|
if (place) {
|
||||||
@@ -99,7 +100,6 @@ export default {
|
|||||||
this.disableAddress = true
|
this.disableAddress = true
|
||||||
} else {
|
} else {
|
||||||
delete this.place.id
|
delete this.place.id
|
||||||
this.place.name = tmpPlace
|
|
||||||
this.place.address = ''
|
this.place.address = ''
|
||||||
this.disableAddress = false
|
this.disableAddress = false
|
||||||
this.$refs.place.blur()
|
this.$refs.place.blur()
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ export default {
|
|||||||
asyncData({ $axios, params, error }) {
|
asyncData({ $axios, params, error }) {
|
||||||
try {
|
try {
|
||||||
const place = params.place
|
const place = params.place
|
||||||
return $axios.$get(`/place/${place}`)
|
return $axios.$get(`/place/${encodeURIComponent(place)}`)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error({ statusCode: 400, message: 'Error!' })
|
error({ statusCode: 400, message: 'Error!' })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,30 @@ const log = require('../../log')
|
|||||||
|
|
||||||
const eventController = {
|
const eventController = {
|
||||||
|
|
||||||
|
async _findOrCreatePlace (body) {
|
||||||
|
if (body.place_id) {
|
||||||
|
const place = await Place.findByPk(body.place_id)
|
||||||
|
if (!place) {
|
||||||
|
throw new Error(`Place not found`)
|
||||||
|
}
|
||||||
|
return place
|
||||||
|
}
|
||||||
|
|
||||||
|
const place_name = body.place_name && body.place_name.trim()
|
||||||
|
const place_address = body.place_address && body.place_address.trim()
|
||||||
|
if (!place_address || !place_name) {
|
||||||
|
throw new Error(`place_id or place_name and place_address are required`)
|
||||||
|
}
|
||||||
|
let place = await Place.findOne({ where: Sequelize.where(Sequelize.fn('LOWER', Sequelize.col('name')), Sequelize.Op.eq, place_name.toLocaleLowerCase()) })
|
||||||
|
if (!place) {
|
||||||
|
place = await Place.create({
|
||||||
|
name: place_name,
|
||||||
|
address: place_address
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return place
|
||||||
|
},
|
||||||
|
|
||||||
async searchMeta(req, res) {
|
async searchMeta(req, res) {
|
||||||
const search = req.query.search
|
const search = req.query.search
|
||||||
|
|
||||||
@@ -389,29 +413,18 @@ const eventController = {
|
|||||||
|
|
||||||
// find or create the place
|
// find or create the place
|
||||||
let place
|
let place
|
||||||
if (body.place_id) {
|
try {
|
||||||
place = await Place.findByPk(body.place_id)
|
place = await eventController._findOrCreatePlace(body)
|
||||||
if (!place) {
|
if (!place) {
|
||||||
return res.status(400).send(`Place not found`)
|
return res.status(400).send(`Place not found`)
|
||||||
}
|
}
|
||||||
} else {
|
} catch (e) {
|
||||||
if (!body.place_name) {
|
return res.status(400).send(e.message)
|
||||||
return res.status(400).send(`Place not found`)
|
|
||||||
}
|
|
||||||
place = await Place.findOne({ where: Sequelize.where(Sequelize.fn('LOWER', Sequelize.col('name')), Op.eq, body.place_name.trim().toLocaleLowerCase()) })
|
|
||||||
if (!place) {
|
|
||||||
if (!body.place_address || !body.place_name) {
|
|
||||||
return res.status(400).send(`place_id or place_name and place_address required`)
|
|
||||||
}
|
|
||||||
place = await Place.create({
|
|
||||||
name: body.place_name,
|
|
||||||
address: body.place_address
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const eventDetails = {
|
const eventDetails = {
|
||||||
title: body.title,
|
title: body.title.trim(),
|
||||||
// sanitize and linkify html
|
// sanitize and linkify html
|
||||||
description: helpers.sanitizeHTML(linkifyHtml(body.description || '')),
|
description: helpers.sanitizeHTML(linkifyHtml(body.description || '')),
|
||||||
multidate: body.multidate,
|
multidate: body.multidate,
|
||||||
@@ -543,27 +556,14 @@ const eventController = {
|
|||||||
|
|
||||||
// find or create the place
|
// find or create the place
|
||||||
let place
|
let place
|
||||||
if (body.place_id) {
|
try {
|
||||||
place = await Place.findByPk(body.place_id)
|
place = await eventController._findOrCreatePlace(body)
|
||||||
if (!place) {
|
if (!place) {
|
||||||
return res.status(400).send(`Place not found`)
|
return res.status(400).send(`Place not found`)
|
||||||
}
|
}
|
||||||
} else {
|
} catch (e) {
|
||||||
if (!body.place_name) {
|
return res.status(400).send(e.message)
|
||||||
return res.status(400).send(`Place not found`)
|
|
||||||
}
|
|
||||||
place = await Place.findOne({ where: Sequelize.where(Sequelize.fn('LOWER', Sequelize.col('name')), Op.eq, body.place_name.trim().toLocaleLowerCase()) })
|
|
||||||
if (!place) {
|
|
||||||
if (!body.place_address || !body.place_name) {
|
|
||||||
return res.status(400).send(`place_id or place_name and place_address required`)
|
|
||||||
}
|
|
||||||
place = await Place.create({
|
|
||||||
name: body.place_name,
|
|
||||||
address: body.place_address
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await event.setPlace(place)
|
await event.setPlace(place)
|
||||||
|
|
||||||
// create/assign tags
|
// create/assign tags
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ describe('Events', () => {
|
|||||||
const required_fields = {
|
const required_fields = {
|
||||||
'title': {},
|
'title': {},
|
||||||
'start_datetime': { title: 'test title' },
|
'start_datetime': { title: 'test title' },
|
||||||
'place_id or place_name and place_address': { title: 'test title', start_datetime: dayjs().unix() + 1000, place_name: 'test place name' },
|
'place_id or place_name and place_address are': { title: 'test title', start_datetime: dayjs().unix() + 1000, place_name: 'test place name' },
|
||||||
}
|
}
|
||||||
|
|
||||||
const promises = Object.keys(required_fields).map(async field => {
|
const promises = Object.keys(required_fields).map(async field => {
|
||||||
@@ -200,9 +200,9 @@ describe('Events', () => {
|
|||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('should trim tags', async () => {
|
test('should trim tags and title', async () => {
|
||||||
const event = {
|
const event = {
|
||||||
title: 'test title 4',
|
title: ' test title 4 ',
|
||||||
place_id: places[0],
|
place_id: places[0],
|
||||||
start_datetime: dayjs().unix() + 1000,
|
start_datetime: dayjs().unix() + 1000,
|
||||||
tags: [' test tag ']
|
tags: [' test tag ']
|
||||||
@@ -213,6 +213,7 @@ describe('Events', () => {
|
|||||||
.expect(200)
|
.expect(200)
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
|
|
||||||
|
expect(response.body.title).toBe('test title 4')
|
||||||
expect(response.body.tags[0]).toBe('test tag')
|
expect(response.body.tags[0]).toBe('test tag')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -300,6 +301,17 @@ describe('Place', () => {
|
|||||||
expect(response.body.length).toBe(2)
|
expect(response.body.length).toBe(2)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('should trim place\'s name and address', async () => {
|
||||||
|
const ret = await request(app).post('/api/event')
|
||||||
|
.send({ title: 'test trimming', place_name: ' test place with white Space ',
|
||||||
|
place_address: ' address with Space ', start_datetime: dayjs().unix() + 1000 })
|
||||||
|
.auth(token.access_token, { type: 'bearer' })
|
||||||
|
.expect(200)
|
||||||
|
|
||||||
|
expect(ret.body.place.name).toBe('test place with white Space')
|
||||||
|
expect(ret.body.place.address).toBe('address with Space')
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
let collections = []
|
let collections = []
|
||||||
@@ -382,20 +394,14 @@ describe('Collection', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test('shoud filter for tags', async () => {
|
test('shoud filter for tags', async () => {
|
||||||
let response = await request(app)
|
await request(app)
|
||||||
.post('/api/filter')
|
.post('/api/filter')
|
||||||
.send({ collectionId: collections[0], tags: ['test'] })
|
.send({ collectionId: collections[0], tags: ['test'] })
|
||||||
.auth(token.access_token, { type: 'bearer' })
|
.auth(token.access_token, { type: 'bearer' })
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
|
|
||||||
// response = await request(app)
|
const response = await request(app)
|
||||||
// .get(`/api/filter/${response.body.id}`)
|
|
||||||
// .auth(token.access_token, { type: 'bearer' })
|
|
||||||
// .expect(200)
|
|
||||||
// expect(response.body.length).toBe(1)
|
|
||||||
|
|
||||||
response = await request(app)
|
|
||||||
.get(`/api/collections/test collection`)
|
.get(`/api/collections/test collection`)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user