@@ -65,22 +65,27 @@ class _AccountRepository extends BaseRepository
6565 if (requests.isEmpty) return [];
6666 var values = QueryValues ();
6767 var rows = await db.execute (
68- Sql .named ('INSERT INTO "accounts" ( "first_name", "last_name", "location", "company_id" )\n '
69- 'VALUES ${requests .map ((r ) => '( ${values .add (r .firstName )}:text, ${values .add (r .lastName )}:text, ${values .add (LatLngConverter ().tryEncode (r .location ))}:point, ${values .add (r .companyId )}:text )' ).join (', ' )}\n '
70- 'RETURNING "id"' ),
68+ Sql .named (
69+ 'INSERT INTO "accounts" ( "first_name", "last_name", "location", "company_id" )\n '
70+ 'VALUES ${requests .map ((r ) => '( ${values .add (r .firstName )}:text, ${values .add (r .lastName )}:text, ${values .add (LatLngConverter ().tryEncode (r .location ))}:point, ${values .add (r .companyId )}:text )' ).join (', ' )}\n '
71+ 'RETURNING "id"' ,
72+ ),
7173 parameters: values.values,
7274 );
7375 var result = rows.map <int >((r) => TextEncoder .i.decode (r.toColumnMap ()['id' ])).toList ();
7476
75- await db.billingAddresses.insertMany (requests.where ((r) => r.billingAddress != null ).map ((r) {
76- return BillingAddressInsertRequest (
77+ await db.billingAddresses.insertMany (
78+ requests.where ((r) => r.billingAddress != null ).map ((r) {
79+ return BillingAddressInsertRequest (
7780 city: r.billingAddress! .city,
7881 postcode: r.billingAddress! .postcode,
7982 name: r.billingAddress! .name,
8083 street: r.billingAddress! .street,
8184 accountId: result[requests.indexOf (r)],
82- companyId: null );
83- }).toList ());
85+ companyId: null ,
86+ );
87+ }).toList (),
88+ );
8489
8590 return result;
8691 }
@@ -90,21 +95,26 @@ class _AccountRepository extends BaseRepository
9095 if (requests.isEmpty) return ;
9196 var values = QueryValues ();
9297 await db.execute (
93- Sql .named ('UPDATE "accounts"\n '
94- 'SET "first_name" = COALESCE(UPDATED."first_name", "accounts"."first_name"), "last_name" = COALESCE(UPDATED."last_name", "accounts"."last_name"), "location" = COALESCE(UPDATED."location", "accounts"."location"), "company_id" = COALESCE(UPDATED."company_id", "accounts"."company_id")\n '
95- 'FROM ( VALUES ${requests .map ((r ) => '( ${values .add (r .id )}:int8::int8, ${values .add (r .firstName )}:text::text, ${values .add (r .lastName )}:text::text, ${values .add (LatLngConverter ().tryEncode (r .location ))}:point::point, ${values .add (r .companyId )}:text::text )' ).join (', ' )} )\n '
96- 'AS UPDATED("id", "first_name", "last_name", "location", "company_id")\n '
97- 'WHERE "accounts"."id" = UPDATED."id"' ),
98+ Sql .named (
99+ 'UPDATE "accounts"\n '
100+ 'SET "first_name" = COALESCE(UPDATED."first_name", "accounts"."first_name"), "last_name" = COALESCE(UPDATED."last_name", "accounts"."last_name"), "location" = COALESCE(UPDATED."location", "accounts"."location"), "company_id" = COALESCE(UPDATED."company_id", "accounts"."company_id")\n '
101+ 'FROM ( VALUES ${requests .map ((r ) => '( ${values .add (r .id )}:int8::int8, ${values .add (r .firstName )}:text::text, ${values .add (r .lastName )}:text::text, ${values .add (LatLngConverter ().tryEncode (r .location ))}:point::point, ${values .add (r .companyId )}:text::text )' ).join (', ' )} )\n '
102+ 'AS UPDATED("id", "first_name", "last_name", "location", "company_id")\n '
103+ 'WHERE "accounts"."id" = UPDATED."id"' ,
104+ ),
98105 parameters: values.values,
99106 );
100- await db.billingAddresses.updateMany (requests.where ((r) => r.billingAddress != null ).map ((r) {
101- return BillingAddressUpdateRequest (
107+ await db.billingAddresses.updateMany (
108+ requests.where ((r) => r.billingAddress != null ).map ((r) {
109+ return BillingAddressUpdateRequest (
102110 city: r.billingAddress! .city,
103111 postcode: r.billingAddress! .postcode,
104112 name: r.billingAddress! .name,
105113 street: r.billingAddress! .street,
106- accountId: r.id);
107- }).toList ());
114+ accountId: r.id,
115+ );
116+ }).toList (),
117+ );
108118 }
109119}
110120
@@ -179,14 +189,15 @@ class FullAccountViewQueryable extends KeyedViewQueryable<FullAccountView, int>
179189
180190 @override
181191 FullAccountView decode (TypedMap map) => FullAccountView (
182- id: map.get ('id' ),
183- firstName: map.get ('first_name' ),
184- lastName: map.get ('last_name' ),
185- location: map.get ('location' , LatLngConverter ().decode),
186- billingAddress: map.getOpt ('billingAddress' , BillingAddressViewQueryable ().decoder),
187- invoices: map.getListOpt ('invoices' , OwnerInvoiceViewQueryable ().decoder) ?? const [],
188- company: map.getOpt ('company' , MemberCompanyViewQueryable ().decoder),
189- parties: map.getListOpt ('parties' , GuestPartyViewQueryable ().decoder) ?? const []);
192+ id: map.get ('id' ),
193+ firstName: map.get ('first_name' ),
194+ lastName: map.get ('last_name' ),
195+ location: map.get ('location' , LatLngConverter ().decode),
196+ billingAddress: map.getOpt ('billingAddress' , BillingAddressViewQueryable ().decoder),
197+ invoices: map.getListOpt ('invoices' , OwnerInvoiceViewQueryable ().decoder) ?? const [],
198+ company: map.getOpt ('company' , MemberCompanyViewQueryable ().decoder),
199+ parties: map.getListOpt ('parties' , GuestPartyViewQueryable ().decoder) ?? const [],
200+ );
190201}
191202
192203class FullAccountView {
@@ -248,14 +259,15 @@ class UserAccountViewQueryable extends KeyedViewQueryable<UserAccountView, int>
248259
249260 @override
250261 UserAccountView decode (TypedMap map) => UserAccountView (
251- id: map.get ('id' ),
252- firstName: map.get ('first_name' ),
253- lastName: map.get ('last_name' ),
254- location: map.get ('location' , LatLngConverter ().decode),
255- billingAddress: map.getOpt ('billingAddress' , BillingAddressViewQueryable ().decoder),
256- invoices: map.getListOpt ('invoices' , OwnerInvoiceViewQueryable ().decoder) ?? const [],
257- company: map.getOpt ('company' , MemberCompanyViewQueryable ().decoder),
258- parties: map.getListOpt ('parties' , GuestPartyViewQueryable ().decoder) ?? const []);
262+ id: map.get ('id' ),
263+ firstName: map.get ('first_name' ),
264+ lastName: map.get ('last_name' ),
265+ location: map.get ('location' , LatLngConverter ().decode),
266+ billingAddress: map.getOpt ('billingAddress' , BillingAddressViewQueryable ().decoder),
267+ invoices: map.getListOpt ('invoices' , OwnerInvoiceViewQueryable ().decoder) ?? const [],
268+ company: map.getOpt ('company' , MemberCompanyViewQueryable ().decoder),
269+ parties: map.getListOpt ('parties' , GuestPartyViewQueryable ().decoder) ?? const [],
270+ );
259271}
260272
261273class UserAccountView {
@@ -306,11 +318,12 @@ class CompanyAccountViewQueryable extends KeyedViewQueryable<CompanyAccountView,
306318
307319 @override
308320 CompanyAccountView decode (TypedMap map) => CompanyAccountView (
309- id: map.get ('id' ),
310- firstName: map.get ('first_name' ),
311- lastName: map.get ('last_name' ),
312- location: map.get ('location' , LatLngConverter ().decode),
313- parties: map.getListOpt ('parties' , CompanyPartyViewQueryable ().decoder) ?? const []);
321+ id: map.get ('id' ),
322+ firstName: map.get ('first_name' ),
323+ lastName: map.get ('last_name' ),
324+ location: map.get ('location' , LatLngConverter ().decode),
325+ parties: map.getListOpt ('parties' , CompanyPartyViewQueryable ().decoder) ?? const [],
326+ );
314327}
315328
316329class CompanyAccountView {
0 commit comments