我使用typeorm在nestjs中管理postgresql数据库。我必须在数据库中保存一个json响应,所以我将整个响应保存在一列中。这是我的实体。`/*eslint禁用更漂亮/更漂亮*/import{Column,CreateDateColumn,Entity,PrimaryGeneratedColumn,UpdateDateColumn}from“typeorm”;
@实体({name:'travel_bookings'})
出口类旅行预订{
@PrimaryGeneratedColumn('uuid') id: string; @Column('uuid') userId:string; @Column({ type: 'json' }) booking_response: string; @Column({ nullable: true }) Status:string; @CreateDateColumn({ name: 'created_at' }) 'created_at': Date; @UpdateDateColumn({ name: 'updated_at' }) 'updated_at': Date;
}`booking_response是一个长的json数据,其中有一个id。现在我正在创建一个函数来更新Status,其中json中的id与我提供的id匹配-
{"type":"flight-order","id":"eJzTd9f397V09w8FAAs4AmY%3D","queuingOfficeId":"NCE4D31SB","associatedRecords":[{"reference":"OM9GOU","creationDate":"2023-02-07T11:40:00.000","originSystemCode":"GDS","flightOfferId":"1"}],"flightOffers":[{"type":"flight-offer","id":"1","source":"GDS","nonHomogeneous":false,"lastTicketingDate":"2023-02-08","itineraries":[{"segments":[{"departure":{"iataCode":"BOS","terminal":"C","at":"2023-03-10T22:55:00"},"arrival":{"iataCode":"LIS","terminal":"1","at":"2023-03-11T10:20:00"},"carrierCode":"TP","number":"216","aircraft":{"code":"32Q"},"duration":"PT6H25M","id":"9","numberOfStops":0,"co2Emissions":[{"weight":303,"weightUnit":"KG","cabin":"ECONOMY"}]},{"departure":{"iataCode":"LIS","terminal":"1","at":"2023-03-11T11:45:00"},"arrival":{"iataCode":"MAD","terminal":"2","at":"2023-03-11T14:05:00"},"carrierCode":"TP","number":"1014","aircraft":{"code":"32Q"},"duration":"PT1H20M","id":"10","numberOfStops":0,"co2Emissions":[{"weight":68,"weightUnit":"KG","cabin":"ECONOMY"}]}]},{"segments":[{"departure":{"iataCode":"MAD","terminal":"2","at":"2023-03-11T21:10:00"},"arrival":{"iataCode":"LIS","terminal":"1","at":"2023-03-11T21:30:00"},"carrierCode":"TP","number":"1019","aircraft":{"code":"321"},"duration":"PT1H20M","id":"83","numberOfStops":0,"co2Emissions":[{"weight":68,"weightUnit":"KG","cabin":"ECONOMY"}]},{"departure":{"iataCode":"LIS","terminal":"1","at":"2023-03-12T11:40:00"},"arrival":{"iataCode":"BOS","terminal":"E","at":"2023-03-12T15:20:00"},"carrierCode":"TP","number":"217","aircraft":{"code":"32Q"},"duration":"PT7H40M","id":"84","numberOfStops":0,"co2Emissions":[{"weight":303,"weightUnit":"KG","cabin":"ECONOMY"}]}]}],"price":{"currency":"USD","total":"613.85","base":"184.00","fees":[{"amount":"0.00","type":"TICKETING"},{"amount":"0.00","type":"SUPPLIER"},{"amount":"0.00","type":"FORM_OF_PAYMENT"}],"grandTotal":"613.85","billingCurrency":"USD"},"pricingOptions":{"fareType":["PUBLISHED"],"includedCheckedBagsOnly":false},"validatingAirlineCodes":["TP"],"travelerPricings":[{"travelerId":"1","fareOption":"STANDARD","travelerType":"ADULT","price":{"currency":"USD","total":"613.85","base":"184.00","taxes":[{"amount":"5.60","code":"AY"},{"amount":"4.40","code":"J9"},{"amount":"15.80","code":"JD"},{"amount":"0.70","code":"OG"},{"amount":"16.10","code":"PT"},{"amount":"3.60","code":"QV"},{"amount":"42.20","code":"US"},{"amount":"3.83","code":"XA"},{"amount":"4.50","code":"XF"},{"amount":"7.00","code":"XY"},{"amount":"6.52","code":"YC"},{"amount":"27.60","code":"YP"},{"amount":"292.00","code":"YQ"}],"refundableTaxes":"86.75"},"fareDetailsBySegment":[{"segmentId":"9","cabin":"ECONOMY","fareBasis":"UUSDSI0E","brandedFare":"DISCOUNT","class":"U","includedCheckedBags":{"quantity":0}},{"segmentId":"10","cabin":"ECONOMY","fareBasis":"UUSDSI0E","brandedFare":"DISCOUNT","class":"U","includedCheckedBags":{"quantity":0}},{"segmentId":"83","cabin":"ECONOMY","fareBasis":"UUSDSI0E","brandedFare":"DISCOUNT","class":"U","includedCheckedBags":{"quantity":0}},{"segmentId":"84","cabin":"ECONOMY","fareBasis":"UUSDSI0E","brandedFare":"DISCOUNT","class":"U","includedCheckedBags":{"quantity":0}}]}]}],"travelers":[{"id":"1","dateOfBirth":"1982-01-16","gender":"MALE","name":{"firstName":"JORGE","lastName":"GONZALES"},"documents":[{"number":"00000000","issuanceDate":"2015-04-14","expiryDate":"2025-04-14","issuanceCountry":"ES","issuanceLocation":"Madrid","nationality":"ES","birthPlace":"Madrid","documentType":"PASSPORT","holder":true}],"contact":{"purpose":"STANDARD","phones":[{"deviceType":"MOBILE","countryCallingCode":"34","number":"480080076"}],"emailAddress":"jorge.gonzales833@telefonica.es"}}],"remarks":{"general":[{"subType":"GENERAL_MISCELLANEOUS","text":"ONLINE BOOKING FROM INCREIBLE VIAJES"}]},"ticketingAgreement":{"option":"DELAY_TO_CANCEL","delay":"6D"},"automatedProcess":[{"code":"IMMEDIATE","queue":{"number":"0","category":"0"},"officeId":"NCE4D31SB"}],"contacts":[{"addresseeName":{"firstName":"PABLO RODRIGUEZ"},"address":{"lines":["Calle Prado, 16"],"postalCode":"28014","countryCode":"ES","cityName":"Madrid"},"purpose":"STANDARD","phones":[{"deviceType":"LANDLINE","countryCallingCode":"34","number":"480080071"},{"deviceType":"MOBILE","countryCallingCode":"33","number":"480080072"}],"companyName":"INCREIBLE VIAJES","emailAddress":"support@increibleviajes.es"}]}
这是我的函数`async-flightCancel(data){
var amadeus = await new Amadeus({ clientId: process.env.API_KEY, clientSecret: process.env.API_SECRET }); // const output=await this.travelBookingsRepo.findOne({where:{ booking_response:"eJzTd9f397V09w8FAAs4AmY%3D"}}) // console.log(output); this.travelBookingsRepo.update({ booking_response: { id: data } },{Status:'Cancelled'}) return amadeus.booking.flightOrder(data).delete();
}`
我使用entityManager、getManager/getConnection在web上找到了一些解决方案,但这些解决方案已被弃用,不再有效。若问题是关于更新函数,那个么我也用findOne和save方法尝试过,但仍然失败。请帮助我解决问题。