Skip to content

Commit

Permalink
ci: (api) removes id from external access
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonymunene committed May 2, 2023
1 parent d83bc4a commit c890300
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 28 deletions.
42 changes: 15 additions & 27 deletions apps/api/src/services/properties/properties.schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//@ts-nocheck
// // For more information about this file see https://dove.feathersjs.com/guides/cli/service.schemas.html
import { resolve, virtual } from '@feathersjs/schema';
import { Type, getDataValidator, getValidator, querySyntax } from '@feathersjs/typebox';
Expand All @@ -7,8 +6,6 @@ import type { Static } from '@feathersjs/typebox';
import type { HookContext } from '../../declarations';
import { dataValidator, queryValidator } from '../../validators';
import { randomUUID } from 'crypto';
import { amenitiesSchema } from '../amenities/amenities.schema';
import { propertyTypesSchema } from '../propertyTypes/propertyTypes.schema';

// Main data model schema
export const propertiesSchema = Type.Object(
Expand All @@ -23,9 +20,9 @@ export const propertiesSchema = Type.Object(
images: Type.Array(Type.Object({ image: Type.String() })),
host: Type.String({ format: 'uuid' }),
propertyTypeId: Type.String(),
propertyType: Type.Ref(propertyTypesSchema),
ownedBy: Type.Array(Type.String()),
amenities: Type.Array(Type.Ref(amenitiesSchema)),
propertyType: Type.String(),
ownedBy: Type.String(),
amenities: Type.Array(Type.String()),
createdAt: Type.String({ format: 'date-time' }),
updatedAt: Type.String({ format: 'date-time' }),
updatedBy: Type.String({ format: 'date-time' }),
Expand All @@ -40,22 +37,19 @@ export const propertiesResolver = resolve<Properties, HookContext>({
userId: property.host,
},
});

const profile = data.map(result => `${result.firstName} ${result.surname}`);
return profile;
return profile.toString();
}),

propertyType: virtual(async (property, context) => {
const propertyType = await context.app
.service('propertyTypes')
.find({
query: {
id: property.propertyTypeId,
},
})
.then(result => {
return result.data.map(result => result.name);
});
const propertyType = await context.app.service('propertyTypes').find({
query: {
id: property.propertyTypeId,
},
});

return propertyType;
return propertyType.data[0].name;
}),
amenities: virtual(async (property, context) => {
const propertyAmenities = await context.app.service('propertyAmenities').find({
Expand All @@ -65,16 +59,10 @@ export const propertiesResolver = resolve<Properties, HookContext>({
},
});

// const propertyAmenityIds = propertyAmenities.data.map(propertyAmenity => propertyAmenity.amenityId);
// TODO: figure out why the $in filter method errors
// const amenities = await context.app.service('amenities').find({ query: { id: { $in: propertyAmenityIds } } });
const propertyAmenityIds = propertyAmenities.data.map(propertyAmenity => propertyAmenity.amenityId);
const amenities = await context.app.service('amenities').find({ query: { id: { $in: propertyAmenityIds } } });

const amenities = await Promise.all(
propertyAmenities.data.map(amenity => context.app.service('amenities').find({ query: { id: amenity.amenityId } }))
).then(result => {
return result.map(result => result.data[0].name);
});
return amenities;
return amenities.data.map(amenity => amenity.name);
}),
});

Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/services/propertyTypes/propertyTypes.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const propertyTypesValidator = getValidator(propertyTypesSchema, dataVali
export const propertyTypesResolver = resolve<PropertyTypes, HookContext>({});

export const propertyTypesExternalResolver = resolve<PropertyTypes, HookContext>({
id: async () => undefined,
createdAt: async () => undefined,
updatedAt: async () => undefined,
updatedBy: async () => undefined,
Expand Down Expand Up @@ -57,7 +58,7 @@ export const propertyTypesPatchResolver = resolve<PropertyTypes, HookContext>({
});

// Schema for allowed query properties
export const propertyTypesQueryProperties = Type.Pick(propertyTypesSchema, ['id', 'name']);
export const propertyTypesQueryProperties = Type.Pick(propertyTypesSchema, ['id']);
export const propertyTypesQuerySchema = Type.Intersect(
[
querySyntax(propertyTypesQueryProperties),
Expand Down

0 comments on commit c890300

Please sign in to comment.