How to save user survey responses to open-ended questions? - mysql

I am designing a MySQL database for storing profiles and user responses to questions from these profiles. Data from the database is needed to create a json objects. We are developing a REST API.
The user fills in the data (name,email, position,tel ...) and thus receives user.id. Then answers survey questions. As a result, user responses are stored in the answer table.
User's response can be prepared in advance in the options table (closed-ended questions). Or maybe not prepared (open-ended questions). Therefore, in addition to the table answer_options, which contains the user's choice of answers (many-to-many), the tableanswer contains the following fields:
text (answer to the question as text),
num (answer to the question as a number),
yn (answer to the question as a boolean type).
The table input_types contains the type of the html element (for example,<input type = "text" />.
The table insert_types contains the name of the field in the table answer (yn,text, num oroptions).
API returns questions as an JSON object:
{
"id": 1,
"label": "Annual turnover of the company?",
"placeholder": "Enter a number",
"required": true,
"input_type": {
"name": "text"
},
"insert_type": {
"name": "num"
}
}
Front-end looks at insert_type send an JSON object relying on it to answer the question:
{
"user": 1,
"question": 1,
"num": 100
}
API recives an object and saves it in the answer table (thenum property is saved in answer.num)
I don't like the fact that the front-end has to concern about insert_type. How is it customary to save user survey responses to open-ended questions?

I had a similar project before. What I did was add user's open ended answers to options table as well, and use the answer_options table for all the answer.
For the front end, it can always send the answer value without specifying the insert type. The backend can find the option_id for close ended questions, or insert the answer for open ended questions and get the option_id. Just for your reference.

Related

Get latest Field from Firestore Collection using a Structured Query?

I am trying to use Zapier to add an email to a SendFox mailing list when a new user gets added to a specified Firestore path. It's asking me for a structured query to find this data.
I am using the one that it's suggesting, but new users aren't being added correctly. My concern is that the structured query isn't set up correctly.
My data is structured as follows:
- Customers (Collection)
- [User ID] (Document)
- EMAIL
- Other Info
- Other Info...
Whenever a new UserID document is added, I'm trying to access the email field in Zapier.
This is the current structured query:
"orderBy": [{
"field": {
"fieldPath": "email"
},
"direction": "DESCENDING"
}]
What is the correct structured query (json) to access the document I'm looking for?
To clarify, it's the latest document in the "customers" collection with the field "email".
I'm not looking fo any javascript code to get this data, merely the correct json structure for this query.
The query you have right now returns all documents from the customers collection in descending order of their email address, so with the zs first. That seems to be unlikely what you want.
Firestore has no built in concept of the most recent document, so what you'll want to do is:
Add a timestamp field to each document that you set to the current time (preferably a server-side timestamp, but client-side will probably work too).
Sort the query on descending values of that new timestamp field.

Does Gsuite support the creation of custom fields that can be used to discover information when used as search strings?

I want to bulk-load some emails in the Gsuite account using a csv file. However there's this field called "building id" which is NOT REQUIRED but is handy for my requirements; I just realized that out of the box, Gsuite cannot locate a record by the mentioned field as the search term. My question is, is there a workaround to this problem? Better yet, does Gsuite support the creation of custom fields that can be used to discover information when used as search strings? Anyone who knows a solution to this problem?
When using the Directory API to list the members, using the query parameter to get the members with a specific buildingId is not an option. The available queries that can be made are listed here.
However, you can create your own custom field using the below Directory API schemas.insert request:
POST https://admin.googleapis.com/admin/directory/v1/customer/{customerId}/schemas
With the following request body:
{
"schemaId": string,
"schemaName": string,
"fields": [
{
"displayName": "",
"fieldName": "",
"fieldType": ""
}
],
"displayName": string,
}
Afterwards, when you want to retrieve the users with a particular value, you will have to make the below request:
GET https://admin.googleapis.com/admin/directory/v1/users
With the following fields:
customFieldMask > set to the name of the schema;
projection > set to custom;
query=schemaName.FIELD='VALUE' > this will query the users who have the field from the custom field with the value 'VALUE'.
Reference
Directory API Users:list;
Directory API Schemas.insert.

How to dynamically avoid sending response containing all properties from relationship data

I am new to spring boot and rest and hence pardon me if this question is very trivial.
I have a situation where the application allows users to register and place order.
On registration of user, the service should be able to send a response with the user information including - User Name, email, contact Number, address etc.
However, while placing orders, I would like the order response object to include within the order details, only the customer (username, email). I do not want to include the address and other information part of the User object.
Currently, what is happening is whenever, I refer to an existing user instance within the Order instance, the Order response has the complete tuple information of the registered user.
In the Order confirmation response, I really do not want the entire User information.
However, if the same Order entity is being referenced for user register, I want the service to include all fields from the Order entity.
I have tried referring to the following links -
Jackson Change JsonIgnore Dynamically
How do I exclude fields with Jackson not using annotations?
However, the solutions mentioned here will always ignore the attribute in response irrespective of the scenario in which the entity is being referenced.
For example - Response from Order service is as below.
{
"id": "ORD-1000",
"priority": null,
"status": "Open",
"customer": {
"id": "1000",
"name": "Avion Solutions",
"email": "support-na#avionsolutions.com",
"contact": null,
"customerType": "gold-sx",
"shipToContactId": null,
"billToContactId": null
},
"urgency": null
}
In the above response tuple, lets say, I just want the order information with basic customer information such as name & email.
And if the customer is registering, then the response should contain all the information as mentioned in the above tuple.
How can i dynamically ignore the attributes in response of the REST service based on the context in which the entity object is being used?
Thanks in advance.
Try to use #JsonView annotation. You can define visibility for given property and on REST Controller you can define level you want to show. For more information and examples, please, read below:
Jackson JSON Views
Jackson – Bidirectional Relationships
Using #JsonView with Spring MVC

Updating particular field in REST call jpa

Am new to REST webservice, i have a scenario where each field in a form to be save to the database as when user fills the field.
So am calling an update API when user goes from one field to another. Using jpa for database operation. The problem am facing here is, lets say for example Employee.
{
"fname":
"lname":
"mname":
"addresses":
{
"line1":
"line2":
}
}
While user fills fname my json will be
{
"fname":"some value"
}
ill call rest to update. And for next field
{
"lname":"another value"
}
in this update case lname will be updated but fname updated with a blank value since am not passing fname. So i have to send full json to have a proper value.
Think if my json is too big with many relation, am feeling just to update one field its not good to pass complete json to the REST API's.
Can somebody give me any idea or any solution for this.
Am developing this with Spring-boot framework
Thanks in advance.

Insert all domain members into Group

I'm currently writing an Add-on to manage Google Groups, and it uses the Admin SDK Directory API to loop through and retrieve all group members and make changes etc.
One curious issue I've found is that when 'All members of the domain' have been added to the group, no member email is supplied. For example, if I retrieve all members of the group, each member will be returned in the format:
{
"kind": "admin#directory#member",
"etag": "\"ABCDEFGHIJKLMNOPQRSTUV123456789\"",
"id": "123455678910",
"email": "email#myDomain.com",
"role": "MEMBER",
"type": "USER"
},
However, if you've added all users within the domain to a group, when you retrieve this 'member', it's returned in the format:
{
"kind": "admin#directory#member",
"etag": "\"ABCDEFGHIJKLMNOPQRSTUV123456789\"",
"id": "123455678910",
"role": "MEMBER",
"type": "CUSTOMER"
},
This is fine for retrieval, as I can identify that it's 'All users in the domain' by the 'type' always being 'Customer', then I just give it an arbitrary email address to display in my interface (I'm using '*#domain.com' just because).
However, when I'm updating the group members list using the 'Insert' method, it requires an email Address (It refers to 'memberkey', but I understand that this must be an email address).
It won't accept dummy addresses such as *#domain.com (It returns an error that this particular address exists, so I gues it's in use in the background), and if I use an existing address and try to overwrite the 'type' from 'User' to 'Customer' in an attempt to convert an existing member to the 'All users' value, this doesn't work (I suspect the 'type' field does not allow 'Customer' as a writable field, only a readable one).
My question: There does not seem to be a method to 'Add all users in the domain' to a group neatly, without looping through the domain and literally adding all members one by one. Does this method exist and I've just missed it? Or is there a neater way to add all members to the group without looping through all the members on the domain and adding them to the group one by one?
No API method has existed for this even back into the provisioning API days. Nothing in Group Settings is different for a group of this kind, it seems to be an unsupported Member Resource. Trying to modify existing members to become type: 'CUSTOMER' also fail.
You can, however, set a single group in the Admin Panel UI to be your "All Members" and then use the address of that group as a proxy member. i.e. it is a propagated all member feature. This is a workaround as opposed to a direct answer, but as I state above the real answer is "No".