Answer the question
In order to leave comments, you need to log in
How to fix error in mongoose schema?
There is a Homepage schema with the firstSection field in it. I want to store in the field firstSection.logo the link file.
All the DTO and schemes that are needed seem to be described. But swears to me on this business all. I don't understand why.
import { Prop, raw, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document, Types } from 'mongoose';
import { File } from '../../file/file.schema';
import { Feedback } from '../../feedback/schemas/feedback.schema';
import { Portfolio } from '../../portfolio/schemas/portfolio.schema';
@Schema()
export class Homepage extends Document {
@Prop(raw({
logo: { type: Types.ObjectId, ref: 'File' },
slogan: String,
title: String,
subtitle: String,
buttonMoreText: String,
}))
firstSection: {
logo: File,
slogan: string,
title: string,
subtitle: string,
buttonMoreText: string,
}
@Prop(raw({
sectionTitle: String,
details: [{ title: String, body: String }],
}))
detailsSection: {
sectionTitle: string,
details: { title: string, body: string }[],
}
@Prop(raw({
sectionTitle: String,
directionsOfDevelopment: [{ title: String, body: String }],
directionsOfDevelopmentExtra: [String]
}))
canIHelpSection: {
sectionTitle: string,
directionsOfDevelopment: { title: string, body: string }[],
directionsOfDevelopmentExtra: string[]
}
@Prop(raw({
sectionTitle: String,
questions: [{ label: String, text: String }],
}))
questionAnswerSection: {
sectionTitle: string,
questions: { label: string, text: string }[],
}
@Prop(raw({
sectionTitle: String,
subtitle: String,
steps: [{ title: String, body: String }],
}))
stepByStepSection: {
sectionTitle: string,
subtitle: string,
steps: { title: string, body: string }[],
}
@Prop(raw({
sectionTitle: String,
subtitle: String,
phone: String,
email: String,
methodOfCommunication: [{ type: String, url: String }],
}))
contactsSection: {
sectionTitle: string,
subtitle: string,
phone: string,
email: string,
methodOfCommunication: { type: string, url: string }[],
}
@Prop(raw({
description: String,
}))
preFooterSection: {
description: string,
}
@Prop(raw({
sectionTitle: String,
feedback: [{ type: Types.ObjectId, ref: 'Feedback' }]
}))
feedbackSection: {
sectionTitle: string,
feedback: [Feedback]
}
@Prop(raw({
sectionTitle: String,
portfolio: [{ type: Types.ObjectId, ref: 'Portfolio' }]
}))
portfolioSection: {
sectionTitle: string,
portfolio: [Portfolio]
}
}
export const HomepageSchema = SchemaFactory.createForClass(Homepage);
src/homepage/homepage.service.ts:26:5 - error TS2322: Type 'Homepage' is not assignable to type 'HomepageDto'.
The types of 'firstSection.logo' are incompatible between these types.
Type 'File' is not assignable to type 'string'.
26 return await this.homepageModel.findOne(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27 {},
~~~~~~~~~
...
30 .populate('feedbackSection.feedback portfolioSection.portfolio')
~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
31 . exec();
~~~~~~~~~~~~~~
src/homepage/homepage.service.ts:39:9 - error TS2769: No overload matches this call.
The last overload gave the following error.
Type 'UpdateFirstSectionDto' is not assignable to type '{ logo: File; slogan:string; title:string; subtitle: string
; buttonMoreText:string; }'.
Types of property 'logo' are incompatible.
Type 'string' is not assignable to type 'File'.
39 { firstSection: updateFirstSectionDto },
~~~~~~~~~~~~
src/homepage/schemas/homapage.schema.ts:16:3
16 firstSection: {
~~~~~~~~~~~~
The expected type comes from property 'firstSection' which is declared here on type 'MongooseUpdateQuery age, "firstSection" | "detailsSection" | "canIHelpSection" | "
section" | "preFooterSection" | "feedbackSection" | "portfolioSection" | "_id">>'
node_modules/@types/mongoose/index.d.ts:3546:5
3546 findOneAndUpdate(conditions: FilterQuery, update: UpdateQuery,
~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~
3547 options: QueryFindOneAndUpdateOptions,
~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~
3548 callback?: (err: any, doc: T | null, res: any) => void): DocumentQuery & Quer
yHelpers;
~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~
~~~~~~~~~
The last overload is declared here.
src/homepage/homepage.service.ts:44:5 - error TS2322: Type '{ logo: File; slogan:string; title:string; subtitle: string
; buttonMoreText:string; }' is not assignable to type 'FirstSectionDto'.
44 return updatedDocument.firstSection;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[12:13:40] Found 3 errors. Watching for file changes.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question