fix: query custom text id fields

This commit is contained in:
Dan Ribbens
2023-05-06 21:25:41 -04:00
parent 2c36468431
commit 967f2ace0e
2 changed files with 9 additions and 1 deletions

View File

@@ -103,7 +103,7 @@ export const sanitizeQueryValue = ({ field, path, operator, val, hasCustomID }:
formattedValue = createArrayFromCommaDelineated(formattedValue);
}
if (path !== '_id') {
if (path !== '_id' || (path === '_id' && hasCustomID && field.type === 'text')) {
if (operator === 'contains') {
formattedValue = { $regex: formattedValue, $options: 'i' };
}

View File

@@ -274,6 +274,14 @@ describe('collections-rest', () => {
expect(foundDoc.id).toEqual(doc.id);
});
it('should query', async () => {
const customId = `custom-${randomBytes(32).toString('hex').slice(0, 12)}`;
const { doc } = await client.create({ slug: customIdSlug, data: { id: customId, name: 'custom-id-name' } });
const { result } = await client.find({ slug: customIdSlug, query: { id: { like: 'custom' } } });
expect(result.docs.map(({ id }) => id)).toContain(doc.id);
});
it('should update', async () => {
const customId = `custom-${randomBytes(32).toString('hex').slice(0, 12)}`;
const { doc } = await client.create({ slug: customIdSlug, data: { id: customId, data: { name: 'custom-id-name' } } });