fix: minor fixes and add csv import support
This commit is contained in:
parent
289e7839c6
commit
fefbf15f5e
6 changed files with 73 additions and 32 deletions
|
@ -94,8 +94,8 @@ function renderCard(organization) {
|
|||
// image
|
||||
let image = createEl('card-image-container')
|
||||
let imageTag = createEl('card-image')
|
||||
//mediaBaseUrl + '/' +
|
||||
imageTag.style = `background-image: url('${organization.thumbnail}')`
|
||||
|
||||
imageTag.style = `background-image: url('${mediaBaseUrl + '/' + organization.thumbnail}')`
|
||||
image.appendChild(imageTag)
|
||||
card.appendChild(image)
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
"@types/multer-s3": "^2.7.7",
|
||||
"@types/mustache": "^4.0.1",
|
||||
"@types/nodemailer": "^6.4.0",
|
||||
"@types/papaparse": "^5.0.4",
|
||||
"@types/papaparse": "^5.0.6",
|
||||
"@types/sanitize-html": "^1.23.3",
|
||||
"@types/twig": "^1.12.3",
|
||||
"aws-sdk": "^2.706.0",
|
||||
|
|
|
@ -6,6 +6,7 @@ import slugify from 'slugify'
|
|||
import { Document } from 'mongoose'
|
||||
import MediaService from '../MediaService'
|
||||
import Utils from '../Utils'
|
||||
import Papa from 'papaparse'
|
||||
|
||||
export default class AdminOrganizationController {
|
||||
static getMany(req: express.Request, res: express.Response) {
|
||||
|
@ -21,11 +22,38 @@ export default class AdminOrganizationController {
|
|||
static import(req: express.Request, res: express.Response) {
|
||||
// first column is always name
|
||||
// second column is always email
|
||||
const data = req.body.csv
|
||||
const input = req.body.data
|
||||
const parsed = Papa.parse(input)
|
||||
if (parsed.errors.length > 0) {
|
||||
return res
|
||||
.status(400)
|
||||
.json({
|
||||
success: false,
|
||||
errors: parsed.errors,
|
||||
_note: 'Invalid import data or csv'
|
||||
})
|
||||
}
|
||||
let promises = parsed.data.map(d => {
|
||||
return AdminOrganizationController.storeUniversal(
|
||||
d[0],
|
||||
d[1].replace(' ', ''),
|
||||
'unaware'
|
||||
)
|
||||
})
|
||||
Promise.all(promises).then(data => {
|
||||
res.json({
|
||||
success: true,
|
||||
input,
|
||||
parsed,
|
||||
data
|
||||
})
|
||||
}).catch(errors => {
|
||||
console.log(errors)
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
errors
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
static store(req: express.Request, res: express.Response) {
|
||||
|
@ -78,9 +106,8 @@ export default class AdminOrganizationController {
|
|||
}
|
||||
}
|
||||
}
|
||||
console.log(body)
|
||||
Organization.create(body).then(data => {
|
||||
AdminOrganizationController.sendEmailTokenUniversal(data)
|
||||
//AdminOrganizationController.sendEmailTokenUniversal(data)
|
||||
resolve({ data, body })
|
||||
}).catch(err => reject(err))
|
||||
})
|
||||
|
|
|
@ -31,23 +31,23 @@ export default class PublicController {
|
|||
if (!isProposed) {
|
||||
organizations = organizations.filter(o => o.get('publishedAt') !== undefined && o.get('publishedAt') !== null)
|
||||
}
|
||||
// let organizationsData = organizations
|
||||
// .map(o => {
|
||||
// const version = isProposed ? o.get('proposedVersion'): o.get('publishedVersion')
|
||||
// return {
|
||||
// _id: o._id,
|
||||
// name: version.name,
|
||||
// description: version.descriptionShort,
|
||||
// thumbnail: version.thumbnail.key,
|
||||
// tags: version.tags === null ? 'tags_not_found' : version.tags,
|
||||
// slug: o.get('slugs')[o.get('slugs).length -1]
|
||||
// }
|
||||
// })
|
||||
let lorem = "Dolore sit tempor et duo ipsum sit sed takimata, et magna voluptua ut sed justo eirmod. Sed tempor justo magna accusam aliquyam sea invidunt eos. Aliquyam accusam vero accusam sed"
|
||||
let organizationsData = []
|
||||
for (var i = 0; i < 40; i++) {
|
||||
organizationsData.push({ _id: i, name: 'Item ' + i, description: lorem, thumbnail: 'https://picsum.photos/800?hash=' + i, slug: 'qsd-'+i, tags: ['5f0e00e1a4dbfe3e0b5291d2'] })
|
||||
let organizationsData = organizations
|
||||
.map(o => {
|
||||
const version = isProposed ? o.get('proposedVersion'): o.get('publishedVersion')
|
||||
return {
|
||||
_id: o._id,
|
||||
name: version.name,
|
||||
description: version.descriptionShort,
|
||||
thumbnail: version.thumbnail.key,
|
||||
tags: version.tags === null ? 'tags_not_found' : version.tags,
|
||||
slug: o.get('slugs')[o.get('slugs').length -1]
|
||||
}
|
||||
})
|
||||
// let lorem = "Dolore sit tempor et duo ipsum sit sed takimata, et magna voluptua ut sed justo eirmod. Sed tempor justo magna accusam aliquyam sea invidunt eos. Aliquyam accusam vero accusam sed"
|
||||
// let organizationsData = []
|
||||
// for (var i = 0; i < 40; i++) {
|
||||
// organizationsData.push({ _id: i, name: 'Item ' + i, description: lorem, thumbnail: 'https://picsum.photos/800?hash=' + i, slug: 'qsd-'+i, tags: ['5f0e00e1a4dbfe3e0b5291d2'] })
|
||||
// }
|
||||
res.render('home.twig', {
|
||||
isProposed,
|
||||
mediaBaseUrl: MediaService.getMediaBaseUrl(),
|
||||
|
|
|
@ -26,6 +26,20 @@ class AllowedString extends mongoose.SchemaType {
|
|||
}
|
||||
}
|
||||
|
||||
const email = {
|
||||
type: String,
|
||||
trim: true,
|
||||
lowercase: true,
|
||||
unique: true,
|
||||
validate: {
|
||||
validator: function(v) {
|
||||
return /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(v);
|
||||
},
|
||||
message: "Invalid email"
|
||||
},
|
||||
required: [true, "Email required"]
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
mongoose.Schema.Types['AllowedString'] = AllowedString
|
||||
|
||||
|
@ -61,7 +75,7 @@ const OrganizationVersion = {
|
|||
phone: { type: String },
|
||||
peoples: [{
|
||||
name: { type: String },
|
||||
email: { type: String },
|
||||
email,
|
||||
phone: { type: String },
|
||||
role: { type: String }
|
||||
}]
|
||||
|
@ -85,7 +99,7 @@ const OrganizationVersion = {
|
|||
|
||||
const Organization = new Schema({
|
||||
adminName: { type: String, required: true },
|
||||
email: { type: String, required: true },
|
||||
email,
|
||||
token: { type: String, required: true },
|
||||
slugs: [{ type: String }], // aliases system
|
||||
validationState: {
|
||||
|
|
|
@ -743,10 +743,10 @@
|
|||
resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz#e486d0d97396d79beedd0a6e33f4534ff6b4973e"
|
||||
integrity sha512-f5j5b/Gf71L+dbqxIpQ4Z2WlmI/mPJ0fOkGGmFgtb6sAu97EPczzbS3/tJKxmcYDj55OX6ssqwDAWOHIYDRDGA==
|
||||
|
||||
"@types/papaparse@^5.0.4":
|
||||
version "5.0.4"
|
||||
resolved "https://registry.yarnpkg.com/@types/papaparse/-/papaparse-5.0.4.tgz#70792c74d9932bcc0bfa945ae7dacfef67f4ee57"
|
||||
integrity sha512-jFv9NcRddMiW4+thmntwZ1AhvMDAX4+tAUDkWWbNcIzgqyjjkuSHOEUPoVh1/gqJTWfDOD1tvl+hSp88W3UtqA==
|
||||
"@types/papaparse@^5.0.6":
|
||||
version "5.0.6"
|
||||
resolved "https://registry.yarnpkg.com/@types/papaparse/-/papaparse-5.0.6.tgz#4fee1a17dc24fed839d276c807f875bd653abbb4"
|
||||
integrity sha512-fCQnycsOSviVLtxuydQ82IhTAv1lSPIA8zY3sYaRHI00lERsa7QSA616HsQZixqEF2asGXZag3hM13N8bm/jAw==
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
|
|
Loading…
Reference in a new issue