Creating Entities using import-jdl - jhipster

I am new in JHipster, creating my first project.
I create the .jdl file using the jdl-studio and now trying to import it using below command.
jhipster import-jdl initial-schema/initial-schema.jdl --debug
which is giving me below error, but the error not giving the specific error like an error with the relationship or creating table command.
Error:-
Error: ERROR! Copying template /Users/deepeshuniyal/Desktop/upwork/employee-managment-system/node_modules/generator-jhipster/generators/entity-server/templates/src/test/java/package/web/rest/EntityResourceIntTest.java.ejs failed. [TypeError: /Users/deepeshuniyal/Desktop/upwork/employee-managment-system/node_modules/generator-jhipster/generators/entity-server/templates/src/test/java/package/web/rest/EntityResourceIntTest.java.ejs:262
260| private static final Long <%=defaultValueName %> = <%= defaultValue %>L;
261| private static final Long <%=updatedValueName %> = <%= updatedValue %>L;
>> 262| <%_ } else if (fieldType === 'Float') { _%>
263|
264| private static final <%=fieldType %> <%=defaultValueName %> = <%= defaultValue %>F;
265| private static final <%=fieldType %> <%=updatedValueName %> = <%= updatedValue %>F;
Cannot read property 'replace' of undefined]
at Environment.error (/Users/deepeshuniyal/Desktop/upwork/employee-managment-system/node_modules/yeoman-environment/lib/environment.js:157:40)
at module.exports.error (/Users/deepeshuniyal/Desktop/upwork/employee-managment-system/node_modules/generator-jhipster/generators/generator-base.js:1516:18)
at ejs.renderFile (/Users/deepeshuniyal/Desktop/upwork/employee-managment-system/node_modules/generator-jhipster/generators/utils.js:207:23)
at tryHandleCache (/Users/deepeshuniyal/Desktop/upwork/employee-managment-system/node_modules/ejs/lib/ejs.js:254:14)
at Object.exports.renderFile (/Users/deepeshuniyal/Desktop/upwork/employee-managment-system/node_modules/ejs/lib/ejs.js:482:10)
at Object.renderContent (/Users/deepeshuniyal/Desktop/upwork/employee-managment-system/node_modules/generator-jhipster/generators/utils.js:203:9)
at module.exports.template (/Users/deepeshuniyal/Desktop/upwork/employee-managment-system/node_modules/generator-jhipster/generators/generator-base-private.js:672:23)
at blockTemplate.templates.forEach.templateObj (/Users/deepeshuniyal/Desktop/upwork/employee-managment-system/node_modules/generator-jhipster/generators/generator-base.js:1936:42)
at Array.forEach (<anonymous>)
at module.exports.writeFilesToDisk (/Users/deepeshuniyal/Desktop/upwork/employee-managment-system/node_modules/generator-jhipster/generators/generator-base.js:1898:45)
Emitted 'error' event at:
at Immediate.setImmediate (/Users/deepeshuniyal/Desktop/upwork/employee-managment-system/node_modules/yeoman-generator/lib/index.js:427:22)
at processImmediate (timers.js:637:19)
My .jdl file is here.
entity Currency {
name String,
code String,
symbol String
}
entity Country {
name String,
code Long,
flagImage BLOB
}
relationship OneToOne {
Country{currency} to Currency
}
entity City{
name String,
code String,
flagImage BLOB
}
relationship OneToMany {
Country{city} to City
}
entity Company {
name String,
code Long,
description String,
address String,
image BLOB
}
relationship OneToMany {
Company{country} to Country
}
entity Employee {
firstname String, lastname String, code Long, description String, address String, email String,
landPhoneNumber String, mobilePhoneNumber String, image BLOB, fileUploadDirectory String
}
relationship ManyToOne {
Employee{country} to Country,
Employee{company} to Company
}
entity Role {
name String, code Long, description String
}
relationship ManyToOne {
Employee{role} to Role
}
entity Appointment {
name String, code Long, description String, address String, startDate LocalDate, endDate LocalDate
}
relationship OneToOne {
Employee{employeeApointment} to Appointment
}
entity Group {
name String, code Long, description String
}
relationship ManyToMany {
Group{employee} to Employee{group}
Employee{group} to Group{employee}
}
entity SubscriptionPack {
name String, code Long, description String, price Double, renewPrice Double, period Double
}
relationship ManyToOne {
SubscriptionPack{currenty} to Currency
}
entity EmployeeSubscription {
subscriptionStart LocalDate, subscriptionEnd LocalDate
}
relationship OneToMany {
Employee{employeeSubscription} to EmployeeSubscription
}
relationship ManyToOne {
EmployeeSubscription{subscriptionPack} to SubscriptionPack
}
entity EmployeeSubscriptionInvoice {
paymentDetailsAtts String
}
relationship OneToOne {
EmployeeSubscription{employeeSubscriptionInvoice} to EmployeeSubscriptionInvoice
}
entity EmployeeSubscriptionInvoicePayment {
paymentDetailsAtts String
}
relationship OneToOne {
EmployeeSubscription{employeeSubscriptionInvoicePayment} to EmployeeSubscriptionInvoicePayment
}
entity EmployeeHolidays {
name String, description String, startDate LocalDate, endDate LocalDate
}
relationship ManyToOne {
Employee{employeeHolidays} to EmployeeHolidays
}
entity PublicHolidays {
name String, description String, startDate LocalDate, endDate LocalDate
}
entity WorkPolicy {
name String, description String, mondayStartTime LocalDate, mondayEndTime LocalDate, mondayBreakStartTime LocalDate, mondayBreakEndTime LocalDate, tuesdayStartTime LocalDate, tuesdayEndTime LocalDate, tuesdayBreakStartTime LocalDate, tuesdayBreakEndTime LocalDate, wednesdayStartTime LocalDate, wednesdayEndTime LocalDate, wednesdayBreakStartTime LocalDate, wednesdayBreakEndTime LocalDate, thursdayStartTime LocalDate, thursdayEndTime LocalDate, thursdayBreakStartTime LocalDate, thursdayBreakEndTime LocalDate, fridayStartTime LocalDate, fridayEndTime LocalDate, fridayBreakStartTime LocalDate, fridayBreakEndTime LocalDate, saturdayStartTime LocalDate, saturdayEndTime LocalDate, saturdayBreakStartTime LocalDate, saturdayBreakEndTime LocalDate, sundayStartTime LocalDate, sundayEndTime LocalDate, sundayBreakStartTime LocalDate, sundayBreakEndTime LocalDate
}
entity Report {
name String, description String, createdOn LocalDate
}
relationship OneToMany {
Employee{employeeReport} to Report
}
entity ReportQuestion {
description String, createdOn LocalDate, dataType String, value String
}
relationship OneToMany {
Report{reportQuestion} to ReportQuestion
}
entity ReportQuestionOption {
description String
}
relationship OneToMany {
ReportQuestion{reportQuestionOption} to ReportQuestionOption
}
entity EmployeeNotification {
byEmail Boolean, onDesktop Boolean, onEveryReport Boolean, onEveryAppointment Boolean, bySMS Boolean
}
relationship OneToMany {
Employee{employeeNotification} to EmployeeNotification
}
entity EmployeeDocuments {
title String, description String, createdOn LocalDate
}
relationship OneToMany {
Employee{employeeDocuments} to EmployeeDocuments
}
paginate all with pagination
dto * with mapstruct
service all with serviceImpl

Your JDL is wrong, BLOB should be spelled as Blob.
See official doc for types: https://www.jhipster.tech/jdl/#types_and_constraints
Also consider using Visual Studio Code with JHipster JDL extension to edit your JDL file, it will highlight errors like this one.

Related

How is the way for me to transfer data from an ITEM that is related to my salesman in the database?

I have this relationship in my schema:
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model Salesman {
id String #id #default(uuid())
username String #unique
password String
contact String #unique
item Item[]
##map("salesman")
}
model Buyer {
id String #id #default(uuid())
username String #unique
password String
##map("buyer")
}
model Item {
id String #id #default(uuid())
item_name String
float_item String
price String
type_skin String
salesman Salesman? #relation(fields: [id_salesman], references: [id])
id_salesman String?
##map("item")
}
i try like this
import { prisma } from "../../../../database/prismaClient" interface IRequest{ username: String, contact: String, id: String } export class GetItemUseCase { async execute({ username, contact, id}: IRequest ){ const info = await prisma.item.findFirst({ where:{id}, select:{ salesman { username, contact, }, } }) } } I tried something like this.
and I'm trying to make a way where when choosing an ITEM, I get the data from that salesman.
but I have no idea how.
What better way to inform?
Sorry, I'm a beginner.
I've tried verifying the relationships and I've tried searching the database.

prisma connectOrCreate create duplicates or return error

I'm trying to seed a bunch of records, on a table that has a many-to-many relationships with another table.
model Resume {
id Int #id #default(autoincrement())
name String
company String?
logo String?
description String?
startDate DateTime?
endDate DateTime?
createdAt DateTime? #default(now()) #map("created_at")
updatedAt DateTime? #map("updated_at")
deletedAt DateTime? #map("deleted_at")
tags ResumeTag[]
##map("resume")
}
model ResumeTag {
id Int #id #default(autoincrement())
name String #unique
resume Resume[]
##map("resume_tags")
}
on script this is what i use using connectOrCreate ( removed other parts, but this is the gist of it):
const resumeSingle = {
id: 1,
company: 'Company A',
name: 'Software Developer',
logo: 'Logo.svg',
description: '',
startDate: moment('2016-06-01').toISOString(),
endDate: null,
tags: ['Node.JS', 'GraphQL', 'PostgreSQL']
};
const { tags, ...resumeData} = resumeSingle;
await prisma.resume.create({
data: {
...resumeData,
tags: {
connectOrCreate: tags.map(tag => ({
where: { name: tag }, create: { name: tag }
}))
},
},
});
I have several records to insert, some with same repeated tags. However the code only stops with error when a new records has a tag already in the db.
Unique constraint failed on the constraint: `name`.
If I remove the unique on name column in ResumeTag it just add duplicated in the db table (with the same name).
I'm using connectOrCreate wrong here?

Cannot return null for non-nullable field Mutation.createAds graphql error

I'm getting Cannot return null for non-nullable field Mutation.createAds. Error in altair graphql any help
I'm trying to upload multiples photos but I'm getting this error!
Hi, I'm getting Cannot return null for non-nullable field Mutation.createAds. Error in altair graphql any help
I'm trying to upload multiples photos but I'm getting this error
type ads {
id: String
user: User
titel: String
discription: String
photo: [photos]
createdAt: String
updatedAt: String
}
type photos{
id: String
photo: String
Adses: ads
createdAt: String
updatedAt: String
}
type Mutation{
createAds( titel: String
discription: String
photo: [Upload]):ads!
}
}
Resolvers
createAds: async (_, {titel,
discription,photo},{LogedInUser}) =>{
userProtect(LogedInUser)
const simo= await MultiplereadFiles(photo)
console.log(simo)
const create = Client.ads.create({data:{
titel,
discription,
photos:simo,
user:{
connect:{
id:LogedInUser.id
}
}
}})
},
Prisma schema
model ads {
id Int #id
user User #relation(fields: [userId], references: [id])
titel String?
discription String
photo photos[]
files String
createdAt DateTime #default(now())
updatedAt DateTime #updatedAt
userId Int
}
model photos {
id Int #id
Adses ads #relation(fields: [adsId], references: [id])
createdAt DateTime #default(now())
updatedAt DateTime #updatedAt
adsId Int
}
The schema indicates a required response.
From the resolver snippet you shared, it seems there's no return to the function. Could it be the reason?
Either that, or there's something broken in your Client.ads.create logic

Defining OpenApi response schemas - particularly the example field - with ServiceStack.Api.OpenApi

When I generate an API spec on SwaggerHub, I can declare the schemas, including user-friendly examples, as follows:
components:
schemas:
Job:
type: object
required:
- position
- department
- startDate
properties:
jobId:
type: integer
format: int32
position:
type: string
example: Copy Boy III
department:
type: string
example: Legal
startDate:
type: string
format: date
example: '2019-10-01'
I can't figure out how to generate the same using the attributes in ServiceStack OpenAPI. Do I put attributes on my Response DTO? Or on my type? I can't find any attribute that seems to correspond to the "example" field.
I've tried using [ApiMember], which looks like the closest possible option, on both the Response DTO and the type the response is tied to, but neither seems to make a difference. Here are a few things I've tried, just in the hopes of seeing a change in the Swagger UI, but neither has worked:
// In the DTO
public class JobResponse
{
[ApiMember(Name = "Job", DataType = "array")] // Will this do anything?
public Job Job { get; set; }
public ResponseStatus ResponseStatus { get; set; } // inject structured errors
}
// In the Type
public class Job : IEntity
{
[Required][DataMember(Name = "jobId")]
public int Id { get; set; }
[ServiceStack.ApiMember(Name = "test", DataType = "string", IsRequired = true)] // Will this do anything?
public string Position { get; set; }
public string Department { get; set; }
public DateTime? StartDate { get; set; }
}
You'd typically use Open API Attributes in order to customize the metadata returned in the generated /openapi specification of your Services.
Attributes to describe the Operation should be on the Request DTO, here's an example of an annotated Request DTO:
[Api("Service Description")]
[Tag("Core Requests")]
[ApiResponse(HttpStatusCode.BadRequest, "Your request was not understood")]
[ApiResponse(HttpStatusCode.InternalServerError, "Oops, something broke")]
[Route("/swagger/{Name}", "GET", Summary = "GET Summary", Notes = "Notes")]
[Route("/swagger/{Name}", "POST", Summary = "POST Summary", Notes="Notes")]
public class MyRequestDto
{
[ApiMember(Name="Name", Description = "Name Description",
ParameterType = "path", DataType = "string", IsRequired = true)]
[ApiAllowableValues("Name", typeof(Color))] //Enum
public string Name { get; set; }
}
You can also use [ApiMember] on normal DTO Type properties if you want to override their default representation.
Whenever you need more fine-grained control over the generated /openapi you can use Operation Filters on the OpenApiFeature plugin, e.g:
Plugins.Add(new OpenApiFeature
{
OperationFilter = (verb, operation) => operation.Tags.Add("all operations")
});
Available configuration options:
ApiDeclarationFilter - allows to modify final result of returned OpenAPI json
OperationFilter - allows to modify operations
SchemaFilter - allows to modify OpenAPI schema for user types
SchemaPropertyFilter - allows to modify propery declarations in
OpenAPI schema

Jhipster User friend self relationship

I want to create a "friend" relationship between User using an entity "Friend".
I try this, but it isn't work.
entity Friend {
status Boolean,
modified LocalDate,
created LocalDate
}
relationship ManyToMany {
Friend{user(login)} to User,
User to Friend{user(login)}
}
How i can do that ?
Thanks
You cannot create relationship with User entity in JDL
A workaround is to create another entity and use a one-to-one relationship like this
entity Friend {
status Boolean,
modified LocalDate,
created LocalDate
}
entity UserExtended {
...
}
relationship OneToOne {
UserExtended to User
}
relationship ManyToMany {
Friend{userExtended(login)} to UserExtended,
UserExtended to Friend{userExtended(login)}
}
You may want to consider creating the relationship with the User directly in the generated code.
Found it :
entity UserExtra {
.....
}
entity Friend{
status Boolean,
modified LocalDate,
created LocalDate
}
relationship OneToOne {
UserExtended{user(login)} to User
}
relationship OneToMany {
UserExtended{friends} to Friend{user}
}
relationship ManyToOne {
UserExtended{friend} to UserExtended{users}
}

Resources