How to properly parse file name from B-form-file dynamic component in BootstrapVue - frontend

I am using the BootstrapVue <component> tag to display components given their name and other properties. My generic component looks like this:
<component :is="componentName" v-model="key" v-bind="properties"></component>
I have a .js file where I define the component together with its properties like this:
{key: '', component: '', properties: { class: '', placeholder: ''} }
In case I want to set BFormFile component my meta data looks like this:
{key: 'file', component: 'BFormFile', properties: { placeholder: 'Upload image here '}
When I upload a file image I want to get the file name and save it in a json object. But I receive an error of the following type:
JSON parse error: Cannot deserialize instance of java.lang.String out of START_OBJECT token (MismatchedInputException)
Could someone give me some opinion about this problem ?

Related

in nestjs how to get dto list that include file?

i want to get dtos that includes file in nestjs.
but i can't find how i get this json array in nestjs.
ex) json array
[
{brand : "A", file : file},
{brand : "B", file : file}
]
dto:
export class fileDto {
brand: string;
file: File;
}
i saw similar question.
File field is not being included in #Body decorator in NestJS
is there any way to get this array in nestjs ?

How to reference generated Prisma schema in my schema.graphql file for a query that filters by id

Trying to add a Query that filters by the unique Id of this object.
Query.js
async function getAbility (root, args, context, info) {
return await context.prisma.ability({
where : {id : args.abilityId}
}, info)
}
This is also defined in my schema.graphql file.
getAbility(where: AbilityWhereUniqueInput) : Ability
I recognize that AbilityWhereUniqueInput comes from the schema generation done with the Prisma CLI however I am unsure how to reference it for the schema.graphql file.
I have attempted to add this at the top of the file:
# import * from './generated/prisma-client/prisma-schema'
But whenever I try to run the application, it is saying that it encounters an unexpected character '.', referring to the first part of the file path i'm providing for the import.
Other Relevant Declarations:
schema.graphql
type Ability {
id: ID!
name: String!
description: String!
imagePath: String!
}
prisma.yml
# Specifies the HTTP endpoint of your Prisma API (deployed to a Prisma Demo server).
endpoint: https://eu1.prisma.sh/public-cookiearm-769/exp-graphql-subscription/dev
# Defines your models, each model is mapped to the database as a table.
datamodel: datamodel.prisma
# Specifies the language and directory for the generated Prisma client.
generate:
- generator: javascript-client
output: ../src/generated/prisma-client
- generator: graphql-schema
output: ../src/generated/prisma.graphql
# Seed your service with initial data based on `seed.graphql`.
seed:
import: seed.graphql
# Ensures Prisma client is re-generated after a datamodel change.
hooks:
post-deploy:
- prisma generate
# If specified, the `secret` must be used to generate a JWT which is attached
# to the `Authorization` header of HTTP requests made against the Prisma API.
# Info: https://www.prisma.io/docs/prisma-graphql-api/reference/authentication-ghd4/
# secret: mysecret123
Here you see I'm generating two files. One for prisma client and other for importing types in schema.graphql.
schema.graphql
# import * from './generated/prisma.graphql'
type Query {
feed: [Post!]!
drafts: [Post!]!
post(id: ID!): Post
}
type Mutation {
createDraft(title: String!, content: String): Post
editPost(id: String!, data: PostUpdateInput!): Post
deletePost(id: ID!): Post
publish(id: ID!): Post
}
type Subscription {
post: Post!
}
type Post {
id: ID!
published: Boolean!
title: String!
content: String!
}
See this line
# import * from './generated/prisma.graphql'
Now I can use PostUpdateInput in schema.graphql
Make sure that you changes the path following yours.
Make sure the imported generated schema is .graphql extension, because you can't import non-graphql files in a graphql file.

Apostrophecms: Allow to upload PDF file only

I am having one field with relation. I want to upload only PDF files. Whereas I don't want to change the default setting for the dgad-attachments from app.js/default.js that allows all office type of files as those are needed in other places in project.
{
name: '_file',
type: 'joinByOne',
withType: 'apostrophe-file',
label: 'File',
required: true,
idField: 'fileId',
filters: {
projection: {
slug: 1,
title: 1,
attachment: 1
}
},
extensions: ['pdf'],
extensionMaps: {},
image: false
}
Can anyone help me on this please?
It sounds like you'll want to create a new file group in Apostrophe-attachments. You can use a file group to specify what types of files and/or extensions should be available when you add an apostrophe-attachments field to an object's schema. In order to add a file group that only contains PDFs, you will want to add this to the modules object in your app.js file:
'apostrophe-attachments': {
fileGroups: [
{
name: 'pdf',
label: 'Pdf',
extensions: ['pdf'],
image: false
}
]
}
This will create a new file group that will only allow files with the extension 'pdf'. Apostrophe-files isn't a regular schema type (it can't be added to an object's schema like other objects can). Instead of using apostrophe-files, it would be better to use apostrophe-attachments, which can be given a file group to restrict what types of files are allowed. In order to specify that group in your attachment, your new field will end up looking like this:
{
name: 'file',
type: 'attachment',
label: 'File',
group: 'pdf',
required: true
}
If you do decide you need to use a join directly to apostrophe-files, you will probably need to add some custom code in order to restrict the file type. If that is the case, you can find more information about apostrophe-files here:
https://apostrophecms.org/docs/modules/apostrophe-files/
You will probably be able to look at the way apostrophe-attachments handles file groups and replicate the behavior if necessary:
https://apostrophecms.org/docs/modules/apostrophe-attachments/

Jade Template Trouble accessing Values from view data

I've passed an object to my jade template from express:
connection.invokeQuery(sqlStatement, function(rows){
res.render('index', { title: 'App', companies: rows});
});
here's my template
extends layout
block content
h1= title
div
each company in companies
p #{company.City}
that works, I can render a city list. But I'm not sure how to get at the root property or sub properties and objects within an object with jade.
For example lets say the json for company was this:
[{
companyName: 'Apple',
City: 'Milwaukee',
State: 'WI ',
StateName: 'Wisconsin',
Country: 'United States',
Region: 'North America',
PostalCode: '53201-0371'},
{
Website: 'www.apple.com',
....
},
... and so on
}]
I tried company.companyName and it doesn't work.
Also how would I reference the property "Website"? It's in another object below in this array.
From what I'm seeing here, you have multiple objects inside an array. You wouldn't be able to access "Website" as it is in another object. The each statement is iterating over the array containing your objects. You could access it in the second iteration of your each statement, but no other properties of the first object. If you wanted access to that value, it must be a part of the same object.

Why doesn't this data display?

I have the following JSON object:
{
user:
{
city: 'San Francisco',
country: 'US',
displayName: 'Bernard',
weightUnit: 'METRIC'
}
}
It comes back in the following piece of code, i.e. as a string:
var response = results[0];
I send it to the view like this:
res.render('user', {title: 'User Details', result: JSON.parse(response)});
In the view, no matter what I do, I cannot access displayName.
All I want is to this in my jade template:
h1 Hi, #{displayName}
And I keep getting user undefined, undefined of undefined, etc.
No matter how I try and access that displayName, jade/express simply cannot get to it.
Anyone have any ideas how I'd do this please?
That object that you pass in your render call becomes the context your Jade file uses. Thus, at your root, you have title and result. See where this is going?
Try h1 Hi, #{result.user.displayName}.

Resources