Duration the survey remains available (in days)
Defines the number of days the survey will be accessible to users after its publication. This value can help automatically expire or hide surveys after a given period.
Example: 7 (1 week), 30 (1 month), 90 (3 months), etc.
Category of the survey
Many-to-one relationship with the Category entity.
Timestamp when the survey was created
Automatically set when the survey is created.
Description of the survey
Provides additional information or context about the survey.
Estimated duration to complete the survey (in minutes)
Represents the estimated time (in minutes) that a participant might take to complete the survey. This is useful for users to know how much time they need to allocate.
Example: 5, 10, 30, etc.
Optional hasUnique identifier for the survey
Auto-generated primary key.
Whether the survey is public
If true, the survey is publicly accessible; otherwise, access is restricted.
Questions in the survey
One-to-many relationship with the Questions entity.
Status of the survey
Indicates the state of the survey (draft, publish, archive, censored).
Defaults to draft.
Title of the survey
A short, unique label that identifies the survey.
Timestamp when the survey was last updated
Automatically updated whenever the survey is modified.
The user who created the survey
Many-to-one relationship with the User entity. CASCADE delete: when user is deleted, surveys are also deleted (RGPD compliance).
Static targetReturns object that is managed by this repository. If this repository manages entity from schema, then it returns a name of that schema instead.
Static averageStatic clearStatic countCounts entities that match given options.
Static countCounts entities that match given WHERE conditions.
Static createCreates a new entity instance.
Creates a new entities and copies all entity properties from given objects into their new entities. Note that it copies only properties that present in entity schema.
Creates a new entity instance and copies all entity properties from this object into a new entity. Note that it copies only properties that present in entity schema.
Static createStatic deleteDeletes entities by a given criteria. Unlike remove method executes a primitive operation without cascades, relations and other operations included. Executes fast and efficient DELETE query. Does not check if entity exist in the database.
Static existsChecks whether any entity exists that matches the given options.
Static existsChecks whether any entity exists that matches the given conditions.
Static findStatic findStatic findStatic findStatic findFinds entities by ids. Optionally find options can be applied.
use findBy method instead in conjunction with In operator, for example:
.findBy({ id: In([1, 2, 3]) })
Static findStatic findStatic findFinds first entity that matches given options.
use findOneBy method instead in conjunction with In operator, for example:
.findOneBy({ id: 1 // where "id" is your primary column name })
Static findStatic findStatic getGets entity mixed id.
Static getStatic hasStatic insertInserts a given entity into the database. Unlike save method executes a primitive operation without cascades, relations and other operations included. Executes fast and efficient INSERT query. Does not check if entity exist in the database, so query will fail if duplicate entity is being inserted.
Static maximumStatic mergeStatic minimumStatic preloadCreates a new entity from the given plain javascript object. If entity already exist in the database, then it loads it (and everything related to it), replaces all values with the new ones from the given object and returns this new entity. This new entity is actually a loaded from the db entity with all properties replaced from the new object.
Note that given entity-like object must have an entity id / primary key to find entity by. Returns undefined if entity with given id was not found.
Static queryExecutes a raw SQL query and returns a raw database results. Raw query execution is supported only by relational databases (MongoDB is not supported).
Optional parameters: any[]Static removeStatic saveSaves all given entities in the database. If entities do not exist in the database then inserts, otherwise updates.
Saves a given entity in the database. If entity does not exist in the database then inserts, otherwise updates.
Static softStatic sumStatic updateUpdates entity partially. Entity can be found by a given conditions. Unlike save method executes a primitive operation without cascades, relations and other operations included. Executes fast and efficient UPDATE query. Does not check if entity exist in the database.
Static upsertInserts a given entity into the database, unless a unique constraint conflicts then updates the entity Unlike save method executes a primitive operation without cascades, relations and other operations included. Executes fast and efficient INSERT ... ON CONFLICT DO UPDATE/ON DUPLICATE KEY UPDATE query.
Static use
Survey Entity
Description
Represents a survey entity in the database.
Param: name
is the entity's name in database.
This class defines the structure of the survey entity in database:
id: unique identifier for the survey.title: title of the survey (must be unique).description: detailed information or context about the survey.status: the current state of the survey (draft,publish,archive,censored), defaults todraft.public: defines whether the survey is accessible publicly or only to selected users.user: the creator of the survey (relation to theUserentity).category: the category to which the survey belongs (relation to theCategoryentity).createdAt: timestamp of when the survey was created.updatedAt: timestamp of when the survey was last updated.Example
Decorators used:
@Entity(): Declares the class as a database entity.@PrimaryGeneratedColumn(): Marks the primary key column with auto-increment.@Column(): Maps a class property to a database column.@ManyToOne(): Defines a many-to-one relationship between entities.@OneToMany(): Defines a one-to-many relationship between entities.@Field(): Exposes a class property to the GraphQL schema.